Jump to content

vmars

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

vmars's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. vmars

    Junction

    I fixed it! Thank you for your assistance everyone!
  2. vmars

    Junction

    Nevermind my last reply, I've fixed that part. My trouble now lies in actually printing this table. I think my table code may be too simple? perhaps? aside from obviously just not working. <?php $username="***"; $password="***"; $database="***"; $host="localhost"; mysql_connect($host,$username,$password); mysql_select_db($database); // Construct our join query $query = "SELECT flags.name, colors.name FROM FlagsColors INNER JOIN flags USING (flags_id) INNER JOIN colors USING (colors_id)"; $result = mysql_query($query) or die(mysql_error()); // Print out the contents of each row into a table echo "<table border='1'> <tr> <th>Flag</th> <th>Colors</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['flags'] . "</td>"; echo "<td>" . $row['colors'] . "</td>"; echo "</tr>"; } echo "</table>"; ?>
  3. vmars

    Junction

    Thanks! I have written my script but my page says the following: "Unknown table 'flags' in field list" Any idea what is wrong with the following code?: (Started the php and connected to mysql...script starts after that) mysql_connect(localhost,$username,$password); @mysql_select_db($database); // Construct join query $query = "SELECT flags.name, colors.name"; "FROM FlagsColors"; "INNER JOIN flags USING ( flags_id )"; "INNER JOIN colors USING ( colors_id )"; $result = mysql_query($query) or die(mysql_error()); // Print out the contents of each row into a table while($row = mysql_fetch_array($result)){ echo $row['Flag']. " - ". $row['Colors']; echo "<br />"; } ?> Your help is greatly appreciated.
  4. vmars

    Junction

    I'm aware I have to use the Join clause, but the Internet examples are proving to be thoroughly confusing. Thank you for any help you can provide!
  5. vmars

    Junction

    mysql> DESCRIBE flags; +----------------+-----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+-----------------------+------+-----+---------+----------------+ | flags_id | mediumint( unsigned| NO | PRI | NULL | auto_increment | | name | tinytext | YES | | NULL | | | directions | text | YES | | NULL | | +----------------+-----------------------+------+-----+---------+----------------+ mysql> DESCRIBE colors; +------------+-----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+-----------------------+------+-----+---------+----------------+ | colors_id | mediumint( unsigned | NO | PRI | NULL | auto_increment | | name | tinytext | YES | | NULL | | | directions | text | YES | | NULL | | +------------+-----------------------+------+-----+---------+----------------+ mysql> DESCRIBE FlagsColors; +----------------+-----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+-----------------------+------+-----+---------+----------------+ | FlagsColors_id | int(10) unsigned | NO | PRI | NULL | auto_increment | | flags_id | mediumint( unsigned | YES | | NULL | | | colors_id | int(10) unsigned | YES | | NULL | | | amount | char(50) | YES | | NULL | | +----------------+-----------------------+------+-----+---------+----------------+ mysql> SELECT * FROM FlagsColors; +--------------+----------------+---------+--------+ | FlagsColors_id | flags_id | colors_id | amount | +--------------+----------------+---------+--------+ | 1 | 1 | 2 | NULL | | 2 | 1 | 4 | NULL | | 3 | 1 | 2 | NULL | | 4 | 2 | 2 | NULL | | 5 | 2 | 3 | NULL | | 6 | 3 | 1 | NULL | | 7 | 3 | 3 | NULL | | 8 | 3 | 6 | NULL | | 9 | 2 | 7 | NULL | | 10 | 3 | 6 | NULL | | 11 | 1 | 5 | NULL | | 12 | 2 | 4 | NULL | | 13 | 3 | 4 | NULL | +--------------+----------------+---------+--------+ So, I'd like it to display Country 1's flag has Blue, Green and Yellow. Country 2's Blue, etc....(Also, I know there is a repeat with Country 1, it's ok...) SOrry the tables are a little messy!
  6. vmars

    Junction

    Hi! I have created two tables, one 'country' [populated with country names] and the other 'flag colors' [populated with the colors of each country's flag]. The junction table combines these two tables. I want to create a page that lists each country and the colors of their respective flags. Obviously this info will be pulled from the junction table, but i am unsure of where to start. I know how to call on mysql in the script to give access to the database, however after that I am unsure of how to print this information. Any ideas of how to start? I've been working on this for a while and just can't figure this out. Thanks in advance!
  7. vmars

    php poll

    poll2.php updated. still needing help: <?php $vote = $_REQUEST['vote']; //get content of textfile $filename = "poll.txt"; $content = file($filename); //put content in array $array = explode("||", $content[0]); $yes = $array[0]; $no = $array[1]; if ($vote == 0) { $cats = $cats + 1; } if ($vote == 1) { $dogs = $dogs + 1; } //insert votes to txt file $insertvote = $cats."||".$dogs; $fp = fopen($filename,"w"); fputs($fp,$insertvote); fclose($fp); ?> <h2>Result:</h2> <table> <tr> <td>Cats:</td> <td> <?php echo(100*round($cats/($dogs+$cats),2)); ?>% </td> </tr> <tr> <td>Dogs:</td> <td> <?php echo(100*round($dogs/($dogs+$cats),2)); ?>% </td> </tr> </table>
  8. vmars

    php poll

    sorry, changed the poll topic and not all of the words. easily fixable! this still won't make em "talk" though.
  9. vmars

    php poll

    HI! I am making a php poll without a database but with a txt file. I have two php scripts (one with the poll, the other with the results) and I am having trouble getting one to talk to the other. Any help is appreciated! Here they are: poll.php <html> <head> <title>POLL!</title> <?PHP $selected_radio = $_POST['album']; print $selected_radio; if (isset($_POST['Submit1'])) { $selected_radio = $_POST['album']; print $selected_radio; } ?> </head> <body> <h1>Cats or Dogs?</h1> <Form name ="form1" Method ="Post" ACTION ="poll.php"> <Input type = 'Radio' Name ='album' value= 'cats'>Cats <Input type = 'Radio' Name ='album' value= 'dogs'>Dogs <P> <Input type = "Submit" Name = "Submit1" Value = "Vote!"> </FORM> <?PHP $usea_status = 'unchecked'; $useb_status = 'unchecked'; if (isset($_POST['Submit1'])) { $selected_radio = $_POST['album']; if ($selected_radio == 'cats') { $cats_status = 'checked'; } elseif ($selected_radio == 'dogs') { $dogs_status = 'checked'; } } ?> </body> </html> ----------- poll2.php <?php $vote = $_REQUEST['vote']; //get content of textfile $filename = "poll.txt"; $content = file($filename); //put content in array $array = explode("||", $content[0]); $yes = $array[0]; $no = $array[1]; if ($vote == 0) { $yes = $yes + 1; } if ($vote == 1) { $no = $no + 1; } //insert votes to txt file $insertvote = $yes."||".$no; $fp = fopen($filename,"w"); fputs($fp,$insertvote); fclose($fp); ?> <h2>Result:</h2> <table> <tr> <td>Cats:</td> <td> <?php echo(100*round($yes/($no+$yes),2)); ?>% </td> </tr> <tr> <td>Dogs:</td> <td> <?php echo(100*round($no/($no+$yes),2)); ?>% </td> </tr> </table>
×
×
  • 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.