Can somebody help me with mySQL ? I want to create a database + table in mySQL with the following columns: 1. Name 2. Type 3. Runs 4. Wickets 5. Team 6. Matches After I've put in records in the mySQL table, I want to be able to fetch these records on HTML pages. Can I get some help, this is sort of urgent ?
You could use PHPMyAdmin to create the table and insert the data. Then, you'll need to write a script in PHP that'll read the data from the table and displays it in a HTML page.
$link = mysql_connect($DBHost, $DBUser, $DBPassword) or die("Impossible connecting to DB - error: ".mysql_errno()." - ".mysql_error()); mysql_select_db($cleanDBName) or die("Impossible selecting DB - error: ".mysql_errno()." - ".mysql_error()); $query = "SELECT field1, field2 FROM tablename"; $result = mysql_query($query) or die("MySQL error - ".mysql_errno()." - ".mysql_error()); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "field1: " . $line['field1'] . "<br/>"; echo "field2: " . $line['field2'] . "<br/>"; } PHP:
1. If I put this script on the page, won't my DB details like username, password etc be visible to anyone ? 2. I plan to display an image along with each record, can I store the image path with the record and retreive it ? If yes, then how ?
Another query, I plan to create a seperate html page for each record, can I add a having field1='abvdcdjas' clause in the statement.
1. You put the script in a file that has the .php extension, like this: example.php <?php $link = mysql_connect($DBHost, $DBUser, $DBPassword) or die("Impossible connecting to DB - error: ".mysql_errno()." - ".mysql_error()); mysql_select_db($cleanDBName) or die("Impossible selecting DB - error: ".mysql_errno()." - ".mysql_error()); $query = "SELECT field1, field2 FROM tablename"; $result = mysql_query($query) or die("MySQL error - ".mysql_errno()." - ".mysql_error()); ?> <html> <head> <title>title</title> </head> <body> <?php while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "field1: " . $line['field1'] . "<br/>"; echo "field2: " . $line['field2'] . "<br/>"; } ?> </body> </html> PHP: Nobody will see your username and password, because all PHP code will be executed server side, and the user will only see the endresult. 2. Yes you can. Add a field (for example a VARCHAR(255)) to your table. Add it to the query in the script. Then, in the while loop, add an echo statement for the <img> . 3. Yes, just add a WHERE field1 = 'whatever' to the query.