just need some help..

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Fatal-X
Forum Newbie
Posts: 5
Joined: Wed May 08, 2002 7:46 pm
Location: Cumberland,MD

just need some help..

Post by Fatal-X »

allrighty lemme explain first.. well i have a crew page for my site, and i just got done writing a "updater" script for the crew members, and so since i did that i had to redo the "crew.php" page, but my problem is getting the data from mysql, to my page as i want it..
heres the code to show the crew members..

Code: Select all

if($action == "show_crew"){
	$connect = mysql_connect("$mysqlhost", "$mysqluser", "$mysqlpass") or die("Couldn't make connection with database");
	mysql_select_db("$mysqldb");
	$result = mysql_query("SELECT crew_user, real_name, job, age, sex, location, languages, hobbies, music, misc FROM crew_profiles");
		if($row = mysql_fetch_array($result)){
			$s_crew_user = $rowї"crew_user"];
			$s_real_name = $rowї"real_name"];
			$s_job = $rowї"job"];
			$s_age = $rowї"age"];
			$s_sex = $rowї"sex"];
			$s_location = $rowї"location"];
			$s_languages = $rowї"languages"];
			$s_hobbies = $rowї"hobbies"];
			$s_music = $rowї"music"];
			$s_misc = $rowї"misc"];

$content = <<<HTML
        <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
          <tr>
            <td bgcolor="#B8B7A4" align="left"><font face="Verdana, Arial, Helvetica" size="1">» <b>$s_crew_user</b></font></td>
          </tr>
          <tr>
            <td bgcolor="#90886A" align="left"><div align="justify"><font face="Verdana, Arial, Helvetica" size="1">
            Name: $s_real_name<br>
            Job: $s_job<br>
            Age: $s_age<br>
            Sex: $s_sex<br>
            Location: $s_location<br>
            Languages: $s_languages<br>
            Hobbies: $s_hobbies<br>
            Music (genre): $s_music<br>
            Misc: $s_misc<br>
           </font></div></td>
          </tr>
        </table>
HTML;
&#125;
&#125;
but what i want it to do is "repeat" the tables for each crew member.. and ive tryed a few different steps.. anybody help?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Fatal-X wrote:but what i want it to do is "repeat" the tables for each crew member..
Try this:

Code: Select all

if($action == "show_crew")&#123; 
	@$connect = mysql_connect($mysqlhost, $mysqluser, $mysqlpass) or die("Couldn't make connection with database"); 
	@mysql_select_db($mysqldb) or die("Couldn't select database"); 
	$result = mysql_query("SELECT crew_user, real_name, job, age, sex, location, languages, hobbies, music, misc FROM crew_profiles");

	for ($i=0; $i<mysql_num_rows($result); ++$i) &#123;
		$row = mysql_fetch_array($result);
			$s_crew_user = $row&#1111;"crew_user"]; 
			$s_real_name = $row&#1111;"real_name"]; 
			$s_job = $row&#1111;"job"]; 
			$s_age = $row&#1111;"age"]; 
			$s_sex = $row&#1111;"sex"]; 
			$s_location = $row&#1111;"location"]; 
			$s_languages = $row&#1111;"languages"]; 
			$s_hobbies = $row&#1111;"hobbies"]; 
			$s_music = $row&#1111;"music"]; 
			$s_misc = $row&#1111;"misc"];

		$content = <<<HTML 
        <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000"> 
          <tr> 
            <td bgcolor="#B8B7A4" align="left"><font face="Verdana, Arial, Helvetica" size="1">» <b>$s_crew_user</b></font></td> 
          </tr> 
          <tr> 
            <td bgcolor="#90886A" align="left"><div align="justify"><font face="Verdana, Arial, Helvetica" size="1"> 
            Name: $s_real_name<br> 
            Job: $s_job<br> 
            Age: $s_age<br> 
            Sex: $s_sex<br> 
            Location: $s_location<br> 
            Languages: $s_languages<br> 
            Hobbies: $s_hobbies<br> 
            Music (genre): $s_music<br> 
            Misc: $s_misc<br> 
           </font></div></td> 
          </tr> 
        </table> 
HTML;
		echo $content;
	&#125;
&#125;
The code will loop through the for array and display the tables one after another (or at least it should but it is early and I am tired). I think that's what you're trying to do.

Mac
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Rather than a for loop use a while loop

while ($Row=MySQL_Fetch_Array($Result)){
$s_crew_user = $Row["crew_user"];
$s_real_name = $Row["real_name"];
.....
}

That way you don't need to determine the number of rows etc. When the mysql_fetch_array() function doesn't find any more records it returns false and the whie statement exits :D
Fatal-X
Forum Newbie
Posts: 5
Joined: Wed May 08, 2002 7:46 pm
Location: Cumberland,MD

Post by Fatal-X »

mikeq - ive allready tryed that a few times,

twigletmac - yes im tryin to reprint the tables for as many "users" that are in the database. but your code seems to give me a parse error, its in the $content though :?

heres what the crew page looks like with the tables, not using the database - crew.php
Fatal-X
Forum Newbie
Posts: 5
Joined: Wed May 08, 2002 7:46 pm
Location: Cumberland,MD

Post by Fatal-X »

hey guys nevermind it's working now..

Code: Select all

<?
if($action == "show_crew")&#123; 
   $connect = mysql_connect("$mysqlhost", "$mysqluser", "$mysqlpass") or die("Couldn't make connection with database"); 
   mysql_select_db("$mysqldb") or die("Couldn't select database"); 
   $result = mysql_query("SELECT crew_user, real_name, job, age, sex, location, languages, hobbies, music, misc FROM crew_profiles"); 
   for ($i=0; $i<mysql_num_rows($result); $i++) &#123;
   $row = mysql_fetch_array($result);
         $s_crew_user = $row&#1111;"crew_user"]; 
         $s_real_name = $row&#1111;"real_name"]; 
         $s_job = $row&#1111;"job"]; 
         $s_age = $row&#1111;"age"]; 
         $s_sex = $row&#1111;"sex"]; 
         $s_location = $row&#1111;"location"]; 
         $s_languages = $row&#1111;"languages"]; 
         $s_hobbies = $row&#1111;"hobbies"]; 
         $s_music = $row&#1111;"music"]; 
         $s_misc = $row&#1111;"misc"]; 

$content = <<<HTML
        <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
          <tr>
            <td bgcolor="#B8B7A4" align="left"><font face="Verdana, Arial, Helvetica" size="1">» <b>$s_crew_user</b></font></td>
          </tr>
          <tr>
            <td bgcolor="#90886A" align="left"><div align="justify"><font face="Verdana, Arial, Helvetica" size="1">
            Name: $s_real_name<br>
            Job: $s_job<br>
            Age: $s_age<br>
            Sex: $s_sex<br>
            Location: $s_location<br>
            Languages: $s_languages<br>
            Hobbies: $s_hobbies<br>
            Music (genre): $s_music<br>
            Misc: $s_misc<br>
           </font></div></td>
          </tr>
        </table>
        <br>
HTML;

    echo $content;
    &#125;
&#125;
?>
thanks guys!
Post Reply