| | |
Return Car Make from MySQL database & have the make hyperlinked.
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2007
Posts: 66
Reputation:
Solved Threads: 14
Just to check, you have actually executed the query, right? And fetched the result with mysql_fetch_assoc?
•
•
Join Date: Nov 2006
Posts: 30
Reputation:
Solved Threads: 0
•
•
•
•
Just to check, you have actually executed the query, right? And fetched the result with mysql_fetch_assoc?
i thought you just entered the:
Select * from bla bla bla bit
then it was selected???
Thanks
•
•
Join Date: Jul 2007
Posts: 66
Reputation:
Solved Threads: 14
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.
See http://no2.php.net/manual/en/ref.mysql.php for more information about the different mysql_* functions.
Hope this helps
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)
// Connect to the database $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } // Select the database you want to use on the server if (!mysql_select_db('databasename', $link)) { die('Could not select database: ' . mysql_error()); } // Create the query-string. Nothing is selected yet $query = "SELECT * FROM cartable"; // Send the query-string to actually perform the query $result = mysql_query($query, $link); if (!$result) { // This happens if there was something wrong with the query die('Invalid query: ' . mysql_error()); } // Iterate over each row the select returned. // mysql_fetch_assoc returns an associative array // http://no2.php.net/manual/en/function.mysql-fetch-assoc.php while ($row = mysql_fetch_assoc($result)) { // Now you can print the hyperlink print("<a href=\''".$row['carwebsiteurl']."\">".$row['carname']."</a>"); } // Close the link when you're done // 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. mysql_close($link);
See http://no2.php.net/manual/en/ref.mysql.php for more information about the different mysql_* functions.
Hope this helps
![]() |
Other Threads in the PHP Forum
- Previous Thread: Supplied argument is not a valid MySQL result resource
- Next Thread: Validation of age?
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube





