Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-03-2005, 01:37 PM   #1 (permalink)
GameOn
Registered User
 
Join Date: May 2005
Posts: 4
GameOn is on a distinguished road
Query returning hyperlink

Hi everyone

Im trying to get a query to return a hyperlink, used a couple of different ways with no success. I would like it to return all the makes in the cardetails table with hyperlinks to a page that has some feilds of the cardetail table of the selected make.

The following code only outputs "Car Details:"

products.php
PHP Code:
<?PHP
include 'connectdb.php';
session_start();

$sql="SELECT make FROM cardetail";

$result mysql_query($sql,$db);
echo 
"Car Details:<br>";
$i=1;
while (
$myrow mysql_fetch_array($result))
{
echo 
"<a href=\"productdetails.php?id=".$myrow["Make"]."\">".$myrow["Model"]."</a><br>";
$i=$i+1;
if(
$i>5)
break;

?>
Heres the connect to database file
PHP Code:
<?PHP

$db
=mysql_connect("localhost""XXX""XXX"
or die(
"Could not connect to localhost."); 

if (!@
mysql_select_db("cardb",$db)) 
    {
    exit(
'Error. Unable to select database.');
        } else {
        
//Connection successful
    
}

?>

Last edited by GameOn; 05-03-2005 at 02:22 PM.
GameOn is offline   Reply With Quote
Old 05-03-2005, 02:12 PM   #2 (permalink)
GameOn
Registered User
 
Join Date: May 2005
Posts: 4
GameOn is on a distinguished road
Also tried this:

Code in index.php
PHP Code:
//Request the car details
$result = @mysql_query('SELECT make FROM cardetail');
$hlink mysql_query($result);

while (
$make mysql_fetch_array($hlink))
               {
                       echo 
"<a href=".$row['make'] .">";
                }

echo 
' <table>
      <tr>
        <td>' 
$row['make'] . '</td>
        <td><a href="products.php" target="_blank">' 
$row['make'] . '</a></td>
        <td>' 
$row['model'] . '</td>
        <td>' 
$row['year'] . '</td>
      </tr>
      </table>'
;

if (!
$result) {
    exit(
'<p>Error performing query: ' mysql_error() . '</p>');

I'm hoping to turn the query results into a page with an order option below.
GameOn is offline   Reply With Quote
Old 06-06-2005, 07:58 AM   #3 (permalink)
draven77
Recruit
 
Join Date: May 2005
Posts: 13
draven77 is on a distinguished road
Try this ----

// Connect up code here

Code:
$result = mysql_query("SELECT make, model FROM cardetail") or die ("no DB connection<br><br>".mysql_error() );
		while($r=mysql_fetch_array($result))
		{    
			// ESTABLISH FIELD NAMES
			$make=$r["make"];
			$model=$r["model"];
			
			echo "<a href=\"productdetails.php?id=$make\">".$model."</a><br />";
		}
Just some advice, it looks like your table may not be structure optimally.. I'd use a car_id. Consider fields like this--

car_id
car_make
car_model

Then you'd pass the id instead of the $make
Code:
echo "<a href=\"productdetails.php?car_id=$car_id\">".$model."</a><br />";
And your query would make more sence on your details page

Code:
SELECT * FROM cardetail WHERE car_id = $car_id
draven77 is offline   Reply With Quote
Old 06-06-2005, 08:21 PM   #4 (permalink)
GameOn
Registered User
 
Join Date: May 2005
Posts: 4
GameOn is on a distinguished road
Thanks a lot for the detailed reply.

I managed to get it going the other day, looking back i can see how clueless i was, and the first example i stumbled across pointed down the wrong path.
I ended up doing something very similar to what you have stated, by displaying the details from the table then having the hyperlink pass the id, with a REQUEST on the page its passing it to so you can display the previous record selected in more depth.

Thanks again.
GameOn is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query string Sonny1973 Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 2 04-11-2005 01:07 PM
Inserting the results of a select query into seperate tables Ste_Boro PHP 1 02-17-2005 06:05 AM
Can someone help with a Query? grwd Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 0 12-31-2004 03:26 PM
a query type of questiton sde Program Design and Methods 6 08-21-2003 05:55 PM
foreach() while() for() or new mysql query? nemesis PHP 6 06-10-2003 07:57 PM


All times are GMT -8. The time now is 11:09 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting