Lambneck Posted April 22, 2008 Share Posted April 22, 2008 Hello, I have a php code that displays a list of links. when a link is chosen it is to display data from mysql database based on the "submission_id" specified by the link chosen. This data would then be displayed on a new "display.php" page. But display.php code currently isn't working. the code of the initial page: $result = mysql_query("SELECT submission_id, col_4 FROM $table ORDER BY submission_date DESC"); if (!$result) { die("Query to show fields from table failed:".mysql_error()); } while($row = mysql_fetch_array($result)) { echo '<a href="Display.php?id='.$row['submission_id'].'">'.$row['col_4'].'</a>'; echo "<br />"; } mysql_free_result($result); Display.php: $id = (int) $_GET['id']; // since the submission ID is named "id" in the query string! $sql = "SELECT * FROM $table WHERE submission_id=$id"; $result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql); if(mysql_num_rows($result) == 1){ $row = mysql_fetch_assoc($sql); //print out information }else{ echo 'That record ID does not exist!'; } ?> I don't see whats wrong with the display.php page code, but its not displaying the data. Can anyone see a problem with it? Quote Link to comment https://forums.phpfreaks.com/topic/102388-solved-display-problem/ Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 if(mysql_num_rows($result) == 1){ $row = mysql_fetch_assoc($sql); //print out information }else{ You aren't actually printing the data. >_> Quote Link to comment https://forums.phpfreaks.com/topic/102388-solved-display-problem/#findComment-524267 Share on other sites More sharing options...
Lambneck Posted April 22, 2008 Author Share Posted April 22, 2008 what would the syntax look like then? ive tried: echo $row; and print $row; with no luck :'( Quote Link to comment https://forums.phpfreaks.com/topic/102388-solved-display-problem/#findComment-524394 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 echo $row['COLUMN_NAME']; mysql_fetch_assoc() returns an array with the keys named as each column, so if you had a column named "name", it'd be in $row['name']. Quote Link to comment https://forums.phpfreaks.com/topic/102388-solved-display-problem/#findComment-524397 Share on other sites More sharing options...
Lambneck Posted April 22, 2008 Author Share Posted April 22, 2008 I tried the following: $id = (int) $_GET['id']; // since the submission ID is named "id" in the query string! $sql = "SELECT * FROM $table WHERE submission_id=$id"; $result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql); if(mysql_num_rows($result) == 1){ $row = mysql_fetch_assoc($sql); echo $row['col_2']; echo $row['col_3']; echo $row['col_4']; echo $row['col_5']; }else{ echo 'That record ID does not exist!'; } ?> However its still not displaying. notice anything else missing? thanks for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/102388-solved-display-problem/#findComment-524468 Share on other sites More sharing options...
phpSensei Posted April 22, 2008 Share Posted April 22, 2008 try $id = mysql_real_escape_string(strip_tags($_GET['id'])); // since the submission ID is named "id" in the query string! $sql = "SELECT * FROM $table WHERE submission_id=$id"; $result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql); if(mysql_num_rows($result) == 1){ $row = mysql_fetch_array($sql); echo $row[0]; }else{ echo 'That record ID does not exist!'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/102388-solved-display-problem/#findComment-524472 Share on other sites More sharing options...
Lambneck Posted April 22, 2008 Author Share Posted April 22, 2008 same result... nothin ??? Quote Link to comment https://forums.phpfreaks.com/topic/102388-solved-display-problem/#findComment-524481 Share on other sites More sharing options...
phpSensei Posted April 22, 2008 Share Posted April 22, 2008 Your using mysql_fetch_array($sql) change it to $result. change $row = mysql_fetch_array($sql); to $row = mysql_fetch_array($result); Quote Link to comment https://forums.phpfreaks.com/topic/102388-solved-display-problem/#findComment-524483 Share on other sites More sharing options...
Lambneck Posted April 22, 2008 Author Share Posted April 22, 2008 sweet its working! Thanks phpSensei Thanks BlackWater Quote Link to comment https://forums.phpfreaks.com/topic/102388-solved-display-problem/#findComment-524491 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.