eMonk Posted May 25, 2011 Share Posted May 25, 2011 Can you add a WHERE clause in $row? For example: $row['city_display'] WHERE city_display = 1 $row['city_display'] WHERE city_display = 2 etc... How can this be done? Quote Link to comment Share on other sites More sharing options...
eMonk Posted May 25, 2011 Author Share Posted May 25, 2011 Right now I'm trying: $id = $_GET['id']; $city_1 = mysql_query("SELECT * FROM model_in_city WHERE city_display = 1 AND model_id = '$id' "); $city_2 = mysql_query("SELECT * FROM model_in_city WHERE city_display = 2 AND model_id = '$id' "); but it's not displaying the correct value in the following text field: <tr> <td>City 1</td> <td><input name="city_1" type="text" size="2" value="<?=$city_1?>" maxlength="2"></td> </tr> However, PHPMYADMIN is showing the correct value. Any ideas? Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 25, 2011 Share Posted May 25, 2011 eMonk: When you do a mysql_query() the mysql server calculates the result. That result then sits on the server. In order to access it you have to fetch the individual rows. This is clearly shown in the php manual, so I'm not going to post it here. There are many different ways to fetch but the one I recommend for most people is mysql_fetch_assoc Quote Link to comment Share on other sites More sharing options...
eMonk Posted May 25, 2011 Author Share Posted May 25, 2011 I was about to post that I just realized that I have to extract the data now but too tired now to play with it. Will continue this tomorrow and write a follow up. Thanks! Quote Link to comment Share on other sites More sharing options...
eMonk Posted May 25, 2011 Author Share Posted May 25, 2011 See anything wrong with this code? $city_1 and $city_2 still aren't showing up in text fields but the data shows correctly in phpmyadmin. $id = $_GET['id']; $qP2 = "SELECT * FROM model_in_city WHERE city_display = 1 AND model_id = '$id' "; $rsP2 = mysql_query($qP2); $row2 = mysql_fetch_array($rsP2); extract($row2); $city_1 = trim($city_display); $qP3 = "SELECT * FROM model_in_city WHERE city_display = 2 AND model_id = '$id' "; $rsP3 = mysql_query($qP3); $row3 = mysql_fetch_array($rsP3); extract($row3); $city_2 = trim($city_display); Quote Link to comment Share on other sites More sharing options...
fugix Posted May 25, 2011 Share Posted May 25, 2011 try this $id = $_GET['id']; $qP2 = "SELECT * FROM model_in_city WHERE city_display = 1 AND model_id = '$id' "; $rsP2 = mysql_query($qP2); $row2 = mysql_fetch_assoc($rsP2); $city_1 = $row2['example_field'] Quote Link to comment Share on other sites More sharing options...
eMonk Posted May 25, 2011 Author Share Posted May 25, 2011 I tried that before fugix but it didn't work. Any more ideas? Added the ; on the last line as well. Quote Link to comment Share on other sites More sharing options...
fugix Posted May 25, 2011 Share Posted May 25, 2011 if you tried that before and it didnt work then you didnt use it correctly...do you have code that shows how you used it? Quote Link to comment Share on other sites More sharing options...
eMonk Posted May 25, 2011 Author Share Posted May 25, 2011 $qP3 = "SELECT * FROM model_in_city WHERE city_display = 2 AND model_id = '$id' "; $rsP3 = mysql_query($qP3); $row3 = mysql_fetch_assoc($rsP3); $city_2 = $row3['city_display']; Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 25, 2011 Share Posted May 25, 2011 eMonk, read this: http://www.flingbits.com/article/view/my-script-with-mysql-calls-doesn-t-work-why-1 Quote Link to comment Share on other sites More sharing options...
fugix Posted May 25, 2011 Share Posted May 25, 2011 what you have there will echo whatever is in you city_display column..if your query is grabbing multiple rows then you'll want to use a while() loop as well..if nothing is getting echoed then try debugging your query e.g $rsP3 = mysql_query($qP3) or die(mysql_error()); edit: gizmola posted right before me...read the link that he posted...should help Quote Link to comment Share on other sites More sharing options...
eMonk Posted May 25, 2011 Author Share Posted May 25, 2011 Ok, I have it working now... $city_2 = $row3['city_display']; should have been $city_2 = $row3['city_id']; however now when i echo $city_2 at the bottom of the page, the value isn't displaying correctly like before. I'm not overwriting the $city_2 variable anywhere. Why is this variable loosing it's value at the bottom of the page? Quote Link to comment Share on other sites More sharing options...
eMonk Posted May 25, 2011 Author Share Posted May 25, 2011 Ah, I have it working now. Just moved this query after a different one. Thanks for the help everyone! Quote Link to comment 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.