Jump to content

Displaying database records


rubiks

Recommended Posts

hello there i am new to all of this and i trying to display recods from the database i have created and i am having errors


[code]             <?
                //connect to mysql
                $db_gigs=mysql_connect("localhost","web22-XXX","XXX
                   if (!$db_gigs) {
                    // db error function
                    echo db_error("$db_gigs");
                    die();
                    }
                   
                //select which database you want to edit
                mysql_select_db("gigs");

                //select the table
                $result = mysql_query("select * from gigs");

                //grab all the content
                while($r=mysql_fetch_array($result)){
               

                //the format is $variable = $r["nameofmysqlcolumn"];

                $id=$r["id"];
                $event=$r["event"];
                $venue=$r["venue"];
                $date=$r["date"];
                $rating=$r["rating"];

                //display the row
                echo "$id <br> $event <br> $venue <br> $date | $rating <br />";
                }
                ?>[/code]

Thats what i have now
and i am getting a error which says

[quote]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/reesweb.co.uk/public_html/mattbay/music.php on line 38[/quote]

Any ideas

thanks Matthew
Link to comment
https://forums.phpfreaks.com/topic/31364-displaying-database-records/
Share on other sites

1) It's not a good idea to show your user and pass for the database. Remove it.

2) Try this, and post the error you get:
[code]<?php

$db_gigs=mysql_connect("localhost","XXX","XXX") or die(mysql_error());

mysql_select_db("gigs") or die(mysql_error());

$result = mysql_query("select * from gigs") or die(mysql_error());

while($r=mysql_fetch_array($result))
{
$id=$r['id'];
$event=$r['event'];
$venue=$r['venue'];
$date=$r['date'];
$rating=$r['rating'];

echo "$id <br> $event <br> $venue <br> $date | $rating <br />";
}
?>[/code]

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.