|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
php mysql help
I was wondering if any one could help me. I am have a database with php and mysql, and it outputs the information on a search. How can I get it to output a link to that specific page of the search results. SO, if you search for cars, it would make a link to that page. http://www.test.com/cars.php
|
|
#2
|
|||
|
|||
|
RE: php mysql help
You are going to need to be a little for specific. Do you already have the info in your database? How is it stored? Are you saying that you already have a functioning search, but it only shows the data and you want it to have a link instead?
|
|
#3
|
|||
|
|||
|
RE: php mysql help
Hey flying what about somthing like this (without any details it is very hard to help)
$result= mysql_query("select * from cars"); if (!$result) { echo("</TABLE>"); echo("<P>Error retrieving cars from database!<BR>". "Error: " . mysql_error()); exit(); } echo "<center><table>n"; while ($r = mysql_fetch_array($result)) { if ($bgcolor == "bgcolor = #C0C0C0") { $bgcolor = "bgcolor = #FFFFFF"; } else { $bgcolor = "bgcolor = #C0C0C0"; } echo("<TR>n"); $Car_link = $r["Car_link"]; $Car_name = $r["Car_name"]; echo("<td $bgcolor><center><font color=#0033af><a href='" . $r["Car_link"] . "'>" . $r["Car_name"] ."</td>n"); echo("</tr>n"); } echo "</center></table>n"; |
|
#4
|
|||
|
|||
|
RE: php mysql help
Hey guys, Im new to this place AND php. I have a similar question. I have set up a page to put data from mySQL in to tables (got the info from this site). I want the data in "item_num" to be a link going to a page with the corresponding item_num.html.
Example Output: 2314 | Ring | Gold Ring I want the "2314" to link to a page 2314.html. Here is what I have so far.... <?PHP $db = mysql_connect("localhost","$login","$password") or die("Problem connecting"); mysql_select_db("jewelryboxnw_com") or die("Problem selecting database"); $query = "SELECT * FROM inventory ORDER BY item_num"; $result = mysql_query($query) or die ("Query failed"); //let's get the number of rows in our result so we can use it in a for loop $numofrows = mysql_num_rows($result); ?> <html> <head><title></title></head> <body> <?PHP echo "<TABLE BORDER="0">n"; echo "<TR bgcolor="lightblue"><TD>Item#</TD><TD>Price</TD><TD>Item</TD><TD>Description</TD></TR>n"; for($i = 0; $i < $numofrows; $i++) { $row = mysql_fetch_array($result); //get a row from our result set if($i % 2) { //this means if there is a remainder echo "<TR bgcolor="#FFFFCC">n"; } else { //if there isn't a remainder we will do the else echo "<TR bgcolor="white">n"; } echo "<TD>".$row['item_num']."</TD><TD>".$row['price']."</TD><TD>".$row['item']."</TD><TD>".$row['desc']."</TD>n"; echo "</TR>n"; } //now let's close the table and be done with it echo "</TABLE>n"; ?> </body> </html> ....the code here probably looks crappy and I am open to ANY suggestions! Thanks! |
|
#5
|
|||
|
|||
|
RE: php mysql help
All you need to do is take this one line :
echo "<TD>".$row['item_num']."</TD><TD>".$row['price']."</TD><TD>".$row['item']."</TD><TD>".$row['desc']."</TD>n"; and change it to something like this : (I have made it two seperate line now just because I find it easier to read): echo "<TD><a href="".$row['item_num'].".html">".$row['item_num']."</a></TD>"; echo "<TD>".$row['price']."</TD><TD>".$row['item']."</TD><TD>".$row['desc']."</TD>n"; Hope that helps... |
|
#6
|
|||
|
|||
|
RE: php mysql help
Thanks Matt! That helps a lot. I'll try it out tonight.
|
|
#7
|
|||
|
|||
|
RE: php mysql help
Woohoo! It works perfect! Thank you!
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > php mysql help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|