eMonk Posted June 16, 2011 Share Posted June 16, 2011 The code below works but the second query is being displayed at the very top of the page. It should be inside the html table. What am I doing wrong? <?php include("../includes/connect.php"); $id = $_GET['id']; $query_1 = "SELECT * FROM model WHERE id = '$id' "; if ($result_1 = $db->query($query_1)) { while ($row = $result_1->fetch_assoc()) { $name = $row['name']; ... ?> <html> <body> <form action="updated.php" method="post"> <table width="600" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="95">Name</td> <td><input type="text" name="name" value="<?=$name?>" maxlength="50"></td> </tr> ... <?php include("../includes/connect.php"); $sel=array(); $query="select a.city_id, a.city_name, b.city_display from city a "; $query .="left outer join model_in_city b on a.city_id=b.city_id and b.city_display>0 and b.model_id=" . $id . " "; $query .="order by a.city_name"; ... ?> Note: I left most of the code out so it isn't too lengthy. Hopefully you can see the logic behind it that I'm try to do. Quote Link to comment https://forums.phpfreaks.com/topic/239590-running-multiple-queries-on-a-page/ Share on other sites More sharing options...
fugix Posted June 16, 2011 Share Posted June 16, 2011 can you show a bigger chunk of the code surrounding the second query, e.x where you actually execute the query and echo the results etc.. much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/239590-running-multiple-queries-on-a-page/#findComment-1230773 Share on other sites More sharing options...
eMonk Posted June 16, 2011 Author Share Posted June 16, 2011 Here's the second query: <?php include("../includes/connect.php"); $sel=array(); $query="select a.city_id, a.city_name, b.city_display from city a "; $query .="left outer join model_in_city b on a.city_id=b.city_id and b.city_display>0 and b.model_id=" . $id . " "; $query .="order by a.city_name"; $city_result=$db->query($query); if ($city_result) { for($i=1;$i<=4;$i++) { $sel[$i]="City " . $i . ":<select name=select[" . $i . "]>\n"; } while ($cityrow = mysqli_fetch_array($city_result)) { for($i=1;$i<=4;$i++) { $sel[$i].="<option value=" . $cityrow['city_id']; if($cityrow['city_display']==$i) { $sel[$i] .=" selected "; } $sel[$i].=">" . $cityrow['city_name'] . "</option>\n"; } } for($i=1;$i<=4;$i++) { $sel[$i].="</select>"; } } else { echo "no city result mysql error=" . mysql_error() . "<br>\n"; } for($i=1;$i<=4;$i++) { echo $sel[$i] . "<br>\n<br>\n"; } ?> Note: I still have to add in the table tags (tr, td, etc) Quote Link to comment https://forums.phpfreaks.com/topic/239590-running-multiple-queries-on-a-page/#findComment-1230777 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.