Jump to content

[SOLVED] help with php page


pumaf1

Recommended Posts

Hi,

I am trying to write a F1 GP database - Yes i know its been done before but it is just a bit of fun for me.

 

What I want to do is get the a list from my SQL database, in this example we are looking for the drivers surname beginning with the letter A. you can see what I have done so far here:

 

http://www.pumaf1.org.uk/members/ib/drivera.php

 

now then when I try and add a column, in this case to show the drivers Nationality, it wont do it. here is the code I have so far:

 

<html>

  <?php
   // listing script
   
   // connect to the server
   mysql_connect(  '', '', '' )
      or die( "Error! Could not connect to database: " . mysql_error() );
   
   // select the database
   mysql_select_db( 'web16-results' )
      or die( "Error! Could not select the database: " . mysql_error() );
   
   // retrieve all the rows from the database
   $query = "SELECT * FROM infobase ";
   $query = "SELECT DISTINCT name FROM infobase WHERE name LIKE 'a%' ORDER BY name asc";
   $results = mysql_query( $query );

   // print out the results
   if( $results )
   {
?>

   
<body bgcolor="#FFFFFF" text="#000000" link="#FF0000" vlink="#FF0000" alink="#FF0000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><div align="center">
</div>
<div align="center"><font size="2" face="verdana"> 
  <? include '../../header.php' ?>
  </font> </div>
<div align="center"> 
  <table width="770" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td height="57" valign="top"> 
        <p> </p>
        <table width="247" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr> 
            <td bgcolor="#FF0000"><div align="center"><font color="#FFFFFF" face="verdana"><strong>"A"</strong></font></div></td>
          </tr>
          <tr> 
            <td><table width="300" border="0" align="center" cellpadding="1" cellspacing="1">
                <?php
      while( $contact = mysql_fetch_object( $results ) )
      {
         // print out the info
         $id     = $contact -> id;
         $name   = $contact -> name;
	 $nat    = $contact -> nat;
	?>
                <tr>
                  <td bgcolor="#CCCCCC"><font size="1" face="verdana"><?php echo( "<a HREF='driveralld.php?name=$name'>$name<br></a>" );?></font></td>
                  <td bgcolor="#CCCCCC"><div align="center"><font size="1" face="verdana"><?php print( "$nat" );?></font></div></td>
                </tr>
                <?		 
         
      }
   }
   else
   {
      die( "Sorry we are having a database problem, please contact admin and report the following error : " . mysql_error() );
   }
   
?>
              </table></td>
          </tr>
        </table>
        <p> </p><div align="center"><a href="javascript:history.go(-1)" class="style1"><font size="2" face="verdana">Back</font></a> 
        </div></td>
    </tr>
  </table>
  <font size="2" face="verdana"> 
  <? include '../../footer.php' ?>
  </font></div>
  
      </body>

 

if anyone could point me in the right direction i would be very happy!

Link to comment
Share on other sites

It wont display the Nationality as you have only told MySQL to return the name of the driver

 

Change your query to:

$query = "SELECT DISTINCT name, nationality FROM infobase WHERE name LIKE 'a%' ORDER BY name asc";

 

Now to display the nationality you'd use

$nationality= $contact->nationality;
echo $nationality;

Within your while loop.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.