943,713 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1426
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Apr 18th, 2009
0

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

$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?
Reputation Points: 45
Solved Threads: 14
Junior Poster in Training
vidaj is offline Offline
66 posts
since Jul 2007
Apr 18th, 2009
0

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

ou will need to paste your code so that we can check what is the actual problem
Reputation Points: 28
Solved Threads: 19
Junior Poster
vicky_rawat is offline Offline
137 posts
since Jun 2008
Apr 19th, 2009
0

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

Click to Expand / Collapse  Quote originally posted by vidaj ...
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
Reputation Points: 10
Solved Threads: 0
Light Poster
jameswoodhouse is offline Offline
30 posts
since Nov 2006
Apr 19th, 2009
0

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

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.

php Syntax (Toggle Plain Text)
  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
Reputation Points: 45
Solved Threads: 14
Junior Poster in Training
vidaj is offline Offline
66 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Supplied argument is not a valid MySQL result resource
Next Thread in PHP Forum Timeline: Validation of age?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC