BadGoat Posted June 7, 2006 Share Posted June 7, 2006 Hello!I am trying to echo multiple values from the same table, which are identified by an ID field. The data makes it into the db, and it works fine when I echo the ID rather than the gear, but when I try to echo the gear, it displays blank. Any ideas?$sqlquery = "INSERT INTO bike VALUES('', '". $_POST['first_gear_id'] ."', '". $_POST['second_gear_id'] ."', '". $_POST['third_gear_id'] ."', '". $_POST['fourth_gear_id'] ."', '". $_POST['fifth_gear_id'] ."')";$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query 1!");$sqlquery = "SELECT * from bike";$get_gear_info = mysql_query("SELECT * FROM gear_ratios WHERE gear_id = '".$_POST['first_gear_id']."'");$row=mysql_fetch_array($get_gear_info);$first_gear_id = $row['first_gear_id'];echo'<tr> <td>First Gear</td> <td>' .$first_gear. '</td></tr>$get_gear_info = mysql_query("SELECT * FROM gear_ratios WHERE gear_id = '".$_POST['second_gear_id']."'");$row=mysql_fetch_array($get_gear_info);$second_gear_id = $row['second_gear_id'];echo'<tr> <td>First Gear</td> <td>' .$second_gear. '</td></tr> Quote Link to comment https://forums.phpfreaks.com/topic/11425-trouble-echoing-multiple-variables-from-the-same-table/ Share on other sites More sharing options...
SharkBait Posted June 7, 2006 Share Posted June 7, 2006 If your pulling multiple values from a table you could through the query in a loop like:[code]// Select all rows in the database$get_gear_info = mysql_query("SELECT * FROM gear_ratios");// Loop through the rows and output themwhile($row = mysql_fetch_array($get_gear_info)) { echo "ID {$row['gear_id']} <br />";}[/code]Then it would output:ID 1ID 2ID 3...Through your whole table. You would also retrieve the other fields via $row['whateverfieldnameis'] Quote Link to comment https://forums.phpfreaks.com/topic/11425-trouble-echoing-multiple-variables-from-the-same-table/#findComment-42888 Share on other sites More sharing options...
BadGoat Posted June 7, 2006 Author Share Posted June 7, 2006 Thank you, I'll give it a try! Quote Link to comment https://forums.phpfreaks.com/topic/11425-trouble-echoing-multiple-variables-from-the-same-table/#findComment-42902 Share on other sites More sharing options...
xyph Posted June 7, 2006 Share Posted June 7, 2006 Also it might help to note that the variable '$first_gear' and '$second_gear' are echoed, yet never defined. Quote Link to comment https://forums.phpfreaks.com/topic/11425-trouble-echoing-multiple-variables-from-the-same-table/#findComment-42933 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.