direct connexion to mysql

A

Anonymous

Guest
Hello

I try to loop a table home like this

Code:
$result = mysql_query("SELECT * FROM home");
echo $result;
if ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$idh = $row("id_home");
$deh = $row("Desc_home");
$coh = $row("Contact_home");
}
}

echo $result; gives me
Resource id #3

But I never get the data which are in home

Can you explain me ?
Thanks
Cordially
Steff
 
try this
Code:
connection to host and db has been selected
$result = mysql_query("SELECT * FROM `home`"); 
if (mysql_num_rows($result)>0) 
   { 
        while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) 
           { 
             $idh =  $row['id_home']; 
             $deh = $row['Desc_home']; 
             $coh = $row['Contact_home']; 
           } 
    }else{
            echo "Nothing in DB table "

           }

will work

when you were testing it with if and then entering in while loop it has already brought one record in your if condition check
 
Thanks

But
Code:
		$selected = mysql_select_db("gestionevt",$dbh) 	or die("Could not select gestionevt");
$result = mysql_query("SELECT * FROM `home`"); 
echo mysql_num_rows($result)."*-";
if (mysql_num_rows($result)>0) 
   { echo "tyy";
        while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) 
           { echo "tyy";
             $idh =  $row['id_home']; 
             $deh = $row['Desc_home']; 
             $coh = $row['Contact_home']; 
           } 
    }else{ 
            echo "Nothing in DB table " ;


           } 	
echo $idh."/".$deh."/".$coh."/";		

		mysql_close($dbh);

gives me 1*-tyytyy///

can you help me ?
thanks
Cordially
Steff
 
what are you trying to output? homes?

Code:
$selected = mysql_select_db("gestionevt",$dbh)    or die("Could not select gestionevt"); 
$result = mysql_query("SELECT * FROM `home`"); 
//echo mysql_num_rows($result)."*-"; 
if (mysql_num_rows($result)>0) 
   {  
        while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) 
           { 

            echo 'Home ID: '. $row['id_home'].'<br>';
            echo 'Home Description: '. $row['Desc_home'].'<br>';
            echo 'Home Contact: '. $row['Contact_home'] .'<br><hr>';
/*
             $idh =  $row['id_home']; 
             $deh = $row['Desc_home']; 
             $coh = $row['Contact_home']; 
*/  
         } 
    }else{ 
            echo "Nothing in DB table " ; 


           }     
//echo $idh."/".$deh."/".$coh."/";       

      mysql_close($dbh);

What does that code get you?
 
Hello

What I try to do

I have one row in home table and I will get it to put it to the screen.

Your script gives :
Home ID:
Home Description:
Home Contact:

I can't get the data which are in home table

Why
I don't understand
Can you explain me?

Thanks
Cordially
Stéphane Vauclaire
 
code given above are good :idea: ... you better read php mysql database functions it will be more clear to you ..... :roll:
 
Back
Top