I think I got the MySQL part of my database correct. After 开发者_运维问答tons of studying, I created an InnoDB database with two tables: Venues and Events.
Each venue has a unique ID (VENUE_ID) that I indexed. Then each event has a column by the name of VENUE_LOCATION that has the ID number of the venue the event belongs to. This is how I have the event table is set up :)
I think that's all good, now I'm having problems getting all of that data displayed using php :/
So far I've done simple stuff such as select data from a single table but I'm lost as to how I can retrieve the information from the events table, AND insert all of the corresponding information from VENUES depending on what number is in 'VENUE_LOCATION'.
And I really have searched up so many examples and tutorials but I have found nothing that exactly shows what I want to do. Any tips as to which direction I should take are greatly appreciated :)! Thanks again
Edit: Here's what I have now
<?php
$dbuser="nightl7_main";
$dbpass="mypw";
$dbname="nightl7_complete"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$result = mysql_query("SELECT * FROM example")
or die(mysql_error());
return $result;
?>
SELECT e.*, v.* FROM Events e
INNER JOIN Venues v ON e.VENUE_LOCATION = v.VENUE_ID
This will select all the information of events and all the information of the venue where the event has taken place.
EDIT
This is the PHP code you could be using for starters:
<?php
$dbuser = 'nightl7_main';
$dbpass = 'mypw';
$dbname = 'nightl7_complete'; //the name of the database
$chandle = mysql_connect('localhost', $dbuser, $dbpass)
or die('Connection Failure to Database');
mysql_select_db($dbname, $chandle) or die ($dbname . ' Database not found. ' . $dbuser);
$query = 'SELECT e.*, v.* FROM Events e '.
'INNER JOIN Venues v ON e.VENUE_LOCATION = v.VENUE_ID';
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo $row['ID'].' '.$row['VENUE_LOCATION'].' '.$row['IMAGE_URL'].'<br />'; // access any column you like here
}
?>
精彩评论