wattsup88 Posted December 21, 2006 Share Posted December 21, 2006 Well this is it... The last step to my giant project... I want to thank everyone who has helped me before now... especially the guru's... The last thing I need help with is... Well, let's start at the beginning so you can understand... I am trying to pass a value from a database to another page when it is clicked to queryed again... I hope that makes sense... Here is the code i have so far:[code]$result = mysql_query("SELECT * FROM jobs ORDER BY id");echo "<table>";$_SESSION['id'] = array();//query displayedwhile ($row = mysql_fetch_array($result)) { $id = $row['id']; // Create multi-dimension array to store all ids$_SESSION['id'][] = $id; // Display IDs in a table echo "<tr><td width=\"200\">$id</td>"; echo "<td width=\"200\"><a href=\"session2.php\">View Job</a></td></tr>";}echo "</table>";mysql_close( $db ); ?>[/code]On the next page, I store all of the ids as variables:[code]<?php$id0 = $_SESSION['id'][0]; $id1 = $_SESSION['id'][1]; $id2 = $_SESSION['id'][2];$id3 = $_SESSION['id'][3];$id4 = $_SESSION['id'][4];$id5 = $_SESSION['id'][5];$id6 = $_SESSION['id'][6];$id7 = $_SESSION['id'][7];$id8 = $_SESSION['id'][8];$id9 = $_SESSION['id'][9];echo $id0;session_destroy();?>[/code]after using this segment of code i would like to be able to tell which of the session['id'] variables were clicked so i can query something else like this:[code]SELECT * FROM jobs WHERE id = 'one of the session[id's]'[/code]i hope this is do able thanks to all in advance as well as the guru's who have helped in the past-Jacob Quote Link to comment Share on other sites More sharing options...
Nhoj Posted December 21, 2006 Share Posted December 21, 2006 I'm not exactly sure exactly what you're trying to do, but If all you're trying to do is pull the info from the DB for the corresponding clicked item you should probably look into using $_GET instead of sessions.Try something like this.....[code]$result = mysql_query('SELECT `id` FROM `jobs` ORDER BY `id` ASC');echo '<table>';//query displayedwhile ($row = mysql_fetch_array($result)) { // Display IDs in a table echo '<tr><td width="200">'.$row['id'].'</td>'; echo '<td width="200"><a href="session2.php?id='.$row['id'].'">View Job</a></td></tr>';}echo '</table>';mysql_close( $db );?>[/code]And in session2.php do something like...[code]$_GET['id'] = preg_replace('|[^0-9]|', '', $_GET['id']);$result = mysql_query('SELECT * FROM `jobs` WHERE `id` = '.$_GET['id'].' LIMIT 1');$found = mysql_num_rows($result);if ($found) {DO SOMETHING} else { echo 'job not found';}[/code] Quote Link to comment Share on other sites More sharing options...
wattsup88 Posted December 21, 2006 Author Share Posted December 21, 2006 great idea man! thanks the only problem is i see that the id number is displayed in the address bar as usual but when i try echoing it, the id doesnt appear (im echoing to test whether the get part works...) here is my code for the first and second pagesfirst page:[code]$result = mysql_query('SELECT `id` FROM `jobs` ORDER BY `id` ASC');echo '<table>';//query displayedwhile ($row = mysql_fetch_array($result)) { // Display IDs in a table echo '<tr><td width="200">'.$row['id'].'</td>'; echo '<td width="200"><a href="session2.php?id='.$row['id'].'">View Job</a></td></tr>';}echo '</table>';mysql_close( $db );?>[/code]second page:[code]<?php$_GET['id'] = preg_replace('|[^0-9]|', '', $_GET['id']);echo '.$_GET['id'].'/*$result = mysql_query('SELECT * FROM `jobs` WHERE `id` = '.$_GET['id'].' LIMIT 1');$found = mysql_num_rows($result);if ($found) {echo $result} else { echo "job not found";}*/?>[/code]sorry to be such a noob lol...thanks Quote Link to comment Share on other sites More sharing options...
trq Posted December 21, 2006 Share Posted December 21, 2006 Variables do not need to be surrounded in quotes, and specifically, if surrounded by single quotes will not be parsed.[code=php:0]echo $_GET['id'];[/code]PS: You do not need this line.[code=php:0]$_GET['id'] = preg_replace('|[^0-9]|', '', $_GET['id']);[/code] Quote Link to comment Share on other sites More sharing options...
Nhoj Posted December 21, 2006 Share Posted December 21, 2006 [quote author=thorpe link=topic=119462.msg489380#msg489380 date=1166673745]PS: You do not need this line.[code=php:0]$_GET['id'] = preg_replace('|[^0-9]|', '', $_GET['id']);[/code][/quote]True, however, that line strips EVERYTHING out of the URL that is not numeric, meaning it helps prevent SQL-Injection... Quote Link to comment Share on other sites More sharing options...
wattsup88 Posted December 22, 2006 Author Share Posted December 22, 2006 Well i certainly don't want SQL injection... I took the quotes out and still no result same thing as before... if you would like to see the page it is "http://www.firstpriorityresources.com/tests/get1.php"... im only trying to get the concept down before i implement it on a larger scale so thats why the page is so simple... 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.