News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

mysql/php query

Started by cannedfool, July 16, 2005, 08:28:43 PM

Previous topic - Next topic

cannedfool

can anyone see why this would not work?

its meant to cycle through the database and show each members details i have selected in a table liek

name      alex
dob         26/06/1985

etc

i get an error on the line past the </html>  line

<?php 
  
  $connection
=mysql_connect("######","#####","######") or die ("could not connect to server");

  
$db mysql_select_db("smf"$connection) or die ("could not connect to database");
 
  
$query "SELECT realName, gender, birthdate, location, avatar, kayak, drink FROM smf_members WHERE ID_GROUP = '1'";
  
  
$result mysql_query($query) or die ("couldnt exec query");
  
  while (
$row mysql_fetch_array($result))
  {
  
extract($row);
echo '
<table width="50%"  border="1" align="center">
<tr>
  <td width="39%" height="136"><span class="style2">Picture:</span></td>
  <td width="61%"><span class="style2"></span></td>
</tr>
<tr>
  <td><span class="style2">Name:</span></td>
  <td><span class="style2">$realName</span></td>
</tr>
<tr>
  <td><span class="style2">Date of Birth : </span></td>
  <td><span class="style2">$birthdate</span></td>
</tr>
<tr>
  <td><span class="style2">Location</span></td>
  <td><span class="style2">$location</span></td>
</tr>
<tr>
  <td><span class="style2">Kayak Paddled:</span></td>
  <td><span class="style2">$kayak</span></td>
</tr>
<tr>
  <td><span class="style2">Quote:</span></td>
  <td><span class="style2"></span></td>
</tr>
<tr>
  <td><span class="style2">Favourite Drink:</span></td>
  <td><span class="style2">$drink</span></td>
</tr>
  </table>
'
;

?>


thanks in advance

kegobeer

Variables are not parsed in single quoted strings; you will get $realName instead of the contents of the variable.  Use this method: echo 'hello ' . $realName . ', nice to meet you.';  You can see excellent examples in the SMF php files.

You are missing the closing } for the while statement.

If you include SSI.php you can use SMF's database functions instead of going thru all the steps to connect to the database, etc.  If you plan on using this elsewhere, why not just add a custom function to SSI.php?
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

cannedfool

this is for use on my website so i did it on there. n dont really know much else.. this is my first bit of php / msql coding

morph

Fixed code would look like this:

<?php 
  
  $connection
=mysql_connect("######","#####","######") or die ("could not connect to server");

  
$db mysql_select_db("smf"$connection) or die ("could not connect to database");
 
  
$query "SELECT realName, gender, birthdate, location, avatar, kayak, drink FROM smf_members WHERE ID_GROUP = '1'";
  
  
$result mysql_query($query) or die ("couldnt exec query");
  
  while (
$row mysql_fetch_array($result))
  {
  
extract($row);
echo '
<table width="50%"  border="1" align="center">
<tr>
  <td width="39%" height="136"><span class="style2">Picture:</span></td>
  <td width="61%"><span class="style2"></span></td>
</tr>
<tr>
  <td><span class="style2">Name:</span></td>
  <td><span class="style2">'
$realName'</span></td>
</tr>
<tr>
  <td><span class="style2">Date of Birth : </span></td>
  <td><span class="style2">'
$birthdate'</span></td>
</tr>
<tr>
  <td><span class="style2">Location</span></td>
  <td><span class="style2">'
$location'</span></td>
</tr>
<tr>
  <td><span class="style2">Kayak Paddled:</span></td>
  <td><span class="style2">'
$kayak'</span></td>
</tr>
<tr>
  <td><span class="style2">Quote:</span></td>
  <td><span class="style2"></span></td>
</tr>
<tr>
  <td><span class="style2">Favourite Drink:</span></td>
  <td><span class="style2">'
$drink'</span></td>
</tr>
  </table>
'
;
  }

?>
[/code

Coming soon!

cannedfool

thanks guys.. i cant believe i was so nervous about writing that. it was soo easy (with a little help)

morph

Yep, but its always good to learn from your mistakes!

Coming soon!

Advertisement: