Page 1 of 1

Retriving Information From My SQL

Posted: Wed May 14, 2003 1:54 pm
by iimrii
Ok in my database there is a table called "say" in that table there are 2 fields one is "player name" and the second is "say"

I modified a code but it is not really enough the fallowing code just lists the "say" field so the out come is like this

sddjska

dsadsadsa

dsadsad

on the web page and here is the code

Code: Select all

<html>
<head>
<title> Log Say </title>
<head>
<body>
<?php
  // Connect to the database server
  $dbcnx = @mysql_connect("localhost", "boyem", "pass", "boyem_com");
  if (!$dbcnx) &#123;
    echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
    exit();
  &#125;
  
  if (! @mysql_select_db("boyem_com") ) &#123;
    echo( "<p>Unable to locate Log Say " .
"database at this time.</p>" );
    exit();
  &#125;
?>
<p> Log Say: </p>
<blockquote>
<?php

   // 
  $result = @mysql_query("SELECT say FROM say");
  if (!$result) &#123;
    echo("<p>Error performing query: " . mysql_error() . "</p>");
    exit();
  &#125;
  // 
  while ( $row = mysql_fetch_array($result) ) &#123;
    echo("<p>" . $row&#1111;"say"] . "</p>");
  &#125;
?>
</blockquote>
</body>
</html>
outcome is here http://www.boyem.com/deneme.php

well as you can see it just lists the says but I want it to be shown like this

player_name: Say

Player_name: say

player_name: say


well of course player_name changes according to what is in the rows.

how can i do that...I am really new to PHP

thanks a lot in advance

Posted: Wed May 14, 2003 1:57 pm
by twigletmac
Try:

Code: Select all

while ( $row = mysql_fetch_array($result) ) { 
    echo '<p>Player Name: ' . $row["say"] . '</p>'; 
}
Mac

Posted: Wed May 14, 2003 2:06 pm
by iimrii
twigletmac wrote:Try:

Code: Select all

while ( $row = mysql_fetch_array($result) ) { 
    echo '<p>Player Name: ' . $row["say"] . '</p>'; 
}
Mac
it wont work it is just gonna wirte Player Name and than say

the table in the database lists like this

player name-----------------------say

momo-------------------------------helloo
devil---------------------------------sup

well in your case it will just write Player Name and dump the says row by row...am I clear??

Posted: Wed May 14, 2003 2:29 pm
by twigletmac
Now it makes more sense. Where does the players name come from? Is it also stored in the say table?

Mac

Posted: Wed May 14, 2003 2:40 pm
by iimrii
some one in another forum helped me out

for future referance here it is

Code: Select all

$result = @mysql_query("SELECT player_name, say FROM say"); 
if (!$result) &#123; 
echo("<p>Error performing query: " . mysql_error() . "</p>"); 
exit(); 
&#125; 
// 
while ( $row = mysql_fetch_array($result) ) &#123; 
echo("<p>" . $row&#1111;'player_name'] . " :: " . $row&#1111;"say"] . "</p>"); 
&#125;