Multiple queries on same page

wxdqz

New Member
Hi
I am trying to execute 3 queries on one php page the first two work great but the last one doesn't execute. Any ideas would be very helpful.


Querie1

<?php
// create connection
$connection = mysql_connect("localhost","root","784847attract")
or die("Couldn't make connection.");

// select database
$db = mysql_select_db("attract", $connection)
or die("Couldn't select database.");


// create SQL statement
$sql = "SELECT pages_title, pages_ref, pages_type, pages_text, pages_photo_ref FROM pages where pages_username = '$username' and pages_ref = '$ref'
ORDER BY pages_order ASC";

// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");

// put data into drop-down list box
$row = (mysql_fetch_array($sql_result));

$ref = $row["pages_ref"];
$maintitle = $row["pages_title"];
$type = $row["pages_type"];
$text = $row["pages_text"];
$imgsrc = $row["pages_photo_ref"];
?>

Querie2

<?

// create connection
$connection = mysql_connect("localhost","root","784847attract")
or die("Couldn't make connection.");

// select database
$db = mysql_select_db("attract", $connection)
or die("Couldn't select database.");


// create SQL statement
$sql = "SELECT pages_title, pages_ref FROM pages where pages_username = '$username'
ORDER BY pages_order ASC";

// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");

// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {

$ref = $row["pages_ref"];
$title = $row["pages_title"];
print ("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>&nbsp;</td>
</tr>
</table>
<table width=\"100%\" border=\"3\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FFFFFF\" bordercolordark=\"#CCCCCC\" bordercolorlight=\"#999999\">
<tr bgcolor=\"#CCCCFF\">
<td><font color=\"#333399\"><b><a href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?ref=$ref&username=$username\">$title</a></b></font></td>
</tr>
</table>");

}

?>


Querie3 (This is the problem one)


<?php
if ($type == "N") {
print "text";
} elseif ($type == "L") {

$connection = mysql_connect("localhost","root","784847attract")
or die("Couldn't make connection.");
$db = mysql_select_db("attract", $connection)
or die("Couldn't select database.");
$sql = "SELECT links_title, links_description, links_url FROM links where links_username = '$username' and links_pageref = '$ref'";
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");


while ($row = mysql_fetch_array($sql_result)) {


$links_title = $row["links_title"];
$links_desc = $row["links_description"];
$links_url = $row["links_url"];
print ("<table width=\"100%\" border=\"2\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#0000FF\">
<tr>
<td width=\"50%\">Title: <a href=http://www.phpbuilder.com/board/archive/index.php/\"http://www.dfg\">$links_title</a></td>
<td width=\"50%\">
<div align=\"right\"><a href=\"http://www.dfg\">Click Here</a></div>
</td>
</tr>
<tr>
<td colspan=\"2\">Description: <font color=\"#CC0033\">$links_desc</font></td>
</tr>
</table>");

}} elseif ($type == "P") {
print "Picture";
} elseif ($type == "C") {
print "Contact";
}
?>

Pretty messy i know but any help is appreciated
 
Back
Top