debuitls Posted August 14, 2009 Share Posted August 14, 2009 Hi I'm printing out a series of individual customer requests dragged from a mysql database. At moment I'm just printing out the whole set of data as one block. $result = mysql_query("SELECT * FROM proposal WHERE username = '$username'"); while($row = mysql_fetch_array($result)) echo "<tbody>"; echo "<tr>"; echo "<td>" . $row['county'] . "</td>"; echo "<td>" . $row['starrating'] . "</td>"; echo "</tr>"; echo "</tbody>"; I want a user to be able to hover over each request individually so that they can select that particular request and go to another page. In other words I want each individual row of data to be individually selectable. Just wondering if anyone had any suggestions on how I would go about doing this? Any help would be really appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/170261-solved-printing-individually-selectable-mysql-rows-to-screen/ Share on other sites More sharing options...
Appzmaster Posted August 14, 2009 Share Posted August 14, 2009 Would making each row a link work for your situation? Quote Link to comment https://forums.phpfreaks.com/topic/170261-solved-printing-individually-selectable-mysql-rows-to-screen/#findComment-898139 Share on other sites More sharing options...
Bricktop Posted August 14, 2009 Share Posted August 14, 2009 Hi debuitls, How about something like: $result = mysql_query("SELECT * FROM proposal WHERE username = '$username'"); while($row = mysql_fetch_array($result)) echo "<tbody>"; echo "<tr>"; echo "<td><a href="STICK THE LINK HERE">" . $row['county'] . "</a></td>"; echo "<td>" . $row['starrating'] . "</td>"; echo "</tr>"; echo "</tbody>"; This would make the "county" text clickable. Or, using JS you could make the whole row clickable by: $result = mysql_query("SELECT * FROM proposal WHERE username = '$username'"); while($row = mysql_fetch_array($result)) echo "<tbody>"; echo "<script type=\"text/javascript\"> function DoNav(theUrl) { document.location.href = theUrl; } </script>"; echo "<tr onclick="DoNav('http://STICK THE LINK HERE/');">"; echo "<td>" . $row['county'] . "</td>"; echo "<td>" . $row['starrating'] . "</td>"; echo "</tr>"; echo "</tbody>"; Quote Link to comment https://forums.phpfreaks.com/topic/170261-solved-printing-individually-selectable-mysql-rows-to-screen/#findComment-898142 Share on other sites More sharing options...
Appzmaster Posted August 14, 2009 Share Posted August 14, 2009 I was just typing that same solution up as a suggestion Quote Link to comment https://forums.phpfreaks.com/topic/170261-solved-printing-individually-selectable-mysql-rows-to-screen/#findComment-898147 Share on other sites More sharing options...
debuitls Posted August 14, 2009 Author Share Posted August 14, 2009 Thanks for getting back to me so quickly! I suppose I just realised that my question is actually a different one to the one I originally asked. So all the rows printed to the screen will be links. And when you press on one of the links it will go to a php page that performs a sql search of the db for more info on that particular proposal. But I suppose my question is how do you link the particular proposal you press on and the subsequent php page that is returned on pressing the link? I'm looking for the same effect as www.tenderme.ie when you press the one of the links Hope I haven't confused. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/170261-solved-printing-individually-selectable-mysql-rows-to-screen/#findComment-898179 Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 You will want to set a get variable to the primary key of the specific entry of the row. for example, if your primary key was the column "id" you would make the link like: <td><a href=\"data.php?id=" . $row['id'] . "\" >" . $row['county'] . "</a></td> hope that helps! EDIT: sorry forgot the second part on the other page (in my example, data.php) you would do a simple SQL query looking for the row with the ID of $_GET['id'], and voila! Hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/170261-solved-printing-individually-selectable-mysql-rows-to-screen/#findComment-898184 Share on other sites More sharing options...
Bricktop Posted August 14, 2009 Share Posted August 14, 2009 Hi debuitls, The website you linked to uses the same method as my second code example, with a slight difference in that they don't call a separate JS function, using your code for example it would look like this: $result = mysql_query("SELECT * FROM proposal WHERE username = '$username'"); while($row = mysql_fetch_array($result)) echo "<tbody>"; echo "<tr onclick=\"window.location='/SOME LINK HERE'\">"; echo "<td>" . $row['county'] . "</td>"; echo "<td>" . $row['starrating'] . "</td>"; echo "</tr>"; echo "</tbody>"; But I'm guessing you also want to know how to make the link go to the specific data you want to display? Just create a function which will display the required data via a $_GET, or create a new page which will grab an identifier via a $_GET and then output it the relevant data based on that identifier. To do it using an external page you would do something like: Create a new page called "results.php" (for example) and populate it with the below: <?php function make_safe($unsafe) { require("YOUR CONNECT FILE"); $safe = mysql_real_escape_string(strip_tags(trim($unsafe))); return $safe; } require("YOUR CONNECT FILE"); $id = make_safe($_GET['id']); $sql = mysql_query("SELECT * FROM YOUR_TABLE WHERE id = '".$id."' ORDER BY id"); while ($a=mysql_fetch_array($sql)) { echo $a['name']; echo $a['email']; etc, etc. } } Then, change your other code to: $result = mysql_query("SELECT * FROM proposal WHERE username = '$username'"); while($row = mysql_fetch_array($result)) echo "<tbody>"; echo "<tr onclick=\"window.location='/results.php&id=$row['id']'\">"; echo "<td>" . $row['county'] . "</td>"; echo "<td>" . $row['starrating'] . "</td>"; echo "</tr>"; echo "</tbody>"; The above is very basic code but should give you an idea of how to achieve what you want. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/170261-solved-printing-individually-selectable-mysql-rows-to-screen/#findComment-898190 Share on other sites More sharing options...
debuitls Posted August 14, 2009 Author Share Posted August 14, 2009 Thanks for your help BrickTop! I have altered the code as you have suggested however when i go to load the first page which has the code while($row = mysql_fetch_array($result)) { echo "<tbody>"; echo "<tr onclick=\"window.location='/results.php&id=$row['[proposalid']'\">"; echo "<td>" . $row['county'] . "</td>"; echo "<td>" . $row['starrating'] . "</td>"; echo "</tr>"; echo "</tbody>"; } ...I'm only getting a blank screen. If I remove the echo "<tr onclick=\"window.location='/results.php&id=$row['[proposalid']'\">"; line the data is printed out as normal. So i'm thinkin there's a small syntax error im missing but havent been able to find it. I also tried mikesta707 suggestion but got a similar blank screen when i loaded the page. Not sure what im doing wrong. Just wondering if anyone has any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/170261-solved-printing-individually-selectable-mysql-rows-to-screen/#findComment-898387 Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 you have an extra square bracket around your $row array's key. this \"window.location='/results.php&id=$row['[proposalid']'\" should be \"window.location='/results.php&id=$row['proposalid']'\" Hope that helps! EDIT: another thing, you must escape the single quotes, or concatenate the array entry to the string. \"window.location='/results.php&id=$row[\'proposalid\']'\" or \"window.location='/results.php&id=" . $row['proposalid'] . "'\" Quote Link to comment https://forums.phpfreaks.com/topic/170261-solved-printing-individually-selectable-mysql-rows-to-screen/#findComment-898391 Share on other sites More sharing options...
debuitls Posted August 15, 2009 Author Share Posted August 15, 2009 Thanks for your help mikesta707 and Bricktop My code is running perfectly now. Quote Link to comment https://forums.phpfreaks.com/topic/170261-solved-printing-individually-selectable-mysql-rows-to-screen/#findComment-898851 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.