Return Car Make from MySQL database & have the make hyperlinked.

Reply

Join Date: Jul 2007
Posts: 66
Reputation: vidaj is an unknown quantity at this point 
Solved Threads: 14
vidaj vidaj is offline Offline
Junior Poster in Training

Re: Return Car Make from MySQL database & have the make hyperlinked.

 
0
  #11
Apr 18th, 2009
Originally Posted by jameswoodhouse View Post
$sql = 'SELECT * FROM cartable';$finalurl = '<a href=\''.$row['carwebsiteurl'].'\'>'.$row['carname'].'</a>';echo $finalurl;


Now it just shows a blank page, no errors though!!!!
Just to check, you have actually executed the query, right? And fetched the result with mysql_fetch_assoc?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 133
Reputation: vicky_rawat is an unknown quantity at this point 
Solved Threads: 17
vicky_rawat's Avatar
vicky_rawat vicky_rawat is offline Offline
Junior Poster

Re: Return Car Make from MySQL database & have the make hyperlinked.

 
0
  #12
Apr 18th, 2009
ou will need to paste your code so that we can check what is the actual problem
Vivek Rawat
Keep solving complexities.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 30
Reputation: jameswoodhouse is an unknown quantity at this point 
Solved Threads: 0
jameswoodhouse jameswoodhouse is offline Offline
Light Poster

Re: Return Car Make from MySQL database & have the make hyperlinked.

 
0
  #13
Apr 19th, 2009
Originally Posted by vidaj View Post
Just to check, you have actually executed the query, right? And fetched the result with mysql_fetch_assoc?
What exactly do you mean by that? Sorry i'm a complete newbie to this stuff.

i thought you just entered the:

Select * from bla bla bla bit

then it was selected???

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 66
Reputation: vidaj is an unknown quantity at this point 
Solved Threads: 14
vidaj vidaj is offline Offline
Junior Poster in Training

Re: Return Car Make from MySQL database & have the make hyperlinked.

 
0
  #14
Apr 19th, 2009
First you have to connect to your mysql_database with your username and password, and select the database you want to use.

Then you create your query (the select statement) and send that query to the server. Then you get your result back, and you can fetch the values.

  1. // Connect to the database
  2. $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
  3. if (!$link) {
  4. die('Could not connect: ' . mysql_error());
  5. }
  6.  
  7. // Select the database you want to use on the server
  8. if (!mysql_select_db('databasename', $link)) {
  9. die('Could not select database: ' . mysql_error());
  10. }
  11.  
  12. // Create the query-string. Nothing is selected yet
  13. $query = "SELECT * FROM cartable";
  14. // Send the query-string to actually perform the query
  15. $result = mysql_query($query, $link);
  16. if (!$result) {
  17. // This happens if there was something wrong with the query
  18. die('Invalid query: ' . mysql_error());
  19. }
  20.  
  21. // Iterate over each row the select returned.
  22. // mysql_fetch_assoc returns an associative array
  23. // http://no2.php.net/manual/en/function.mysql-fetch-assoc.php
  24. while ($row = mysql_fetch_assoc($result)) {
  25. // Now you can print the hyperlink
  26. print("<a href=\''".$row['carwebsiteurl']."\">".$row['carname']."</a>");
  27. }
  28.  
  29. // Close the link when you're done
  30. // This is also done automatically when the script ends. Do not open and close database connections for every query you do. You open one global connection to the database, and let all the scripts you execute use that one.
  31. mysql_close($link);

See http://no2.php.net/manual/en/ref.mysql.php for more information about the different mysql_* functions.

Hope this helps
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC