Hi, I have been trying to solve this for ages and just can’t seem to get it right.
I want to do 2 things here, i am getting an array out of a mysql database (i am getting the user’s id) and then converting that array into a string and using that string to get information out of another database.
i am trying to use the implode function $string=implode("OR id =" , $userid)
here is what i am trying to achieve: mysql_query(mysql stuf... WHERE id = $string) this should now equal: mysql_query(blah blah blah WHERE id = 1 OR id = 5 OR id = 19) because that is what is inside that vaiable now.
The problem i am having is i can't seem to get multiple rows out of my database, it only loads one.
when i echo out my array it said this Array ( [0] => 9 [ID] => 9 [1] => 19 [userid] => 19 [2] => 0 [approved] => 0 )
ALso i have tried a few differnt things with the imploe function at the moment i think it is coming up with an error.
anyway here is my code. i hope someone can help :)
<?php
$username = $_COOKIE['user'];
@mysql_connect ("localhost","down2par_down2pa","4m329aMh") or die ("could not connect to MySQL");
@mysql_select_db ("down2par_d2pdb") or die ("no database");
$query1 =mysql_query("SELECT * FROM login WHERE username = '$username'");
$user = mysql_fetch_array($query1);
$admin = $user['admin'];
if ($admin==1){
//get user id from "approval" database
$query2 =mysql_query("SELECT * FROM approval WHERE approved = '0'");
$result =mysql_fetch_array($query2);
//turn array of ids into a string
$string = implode(" OR id =", $result['userid']);
//get total number of users
$numrow = mysql_num_rows($query2);
//use string to get users details from "login" database
$query =mysql_query("SELECT * FROM login WHERE id ='$string'");
echo ('
<html>
<head>
<style type="text/css">
td {
//padding-left: 10px;
//padding-right: 10px;
}
table {
border: solid grey 2px;
margin: 5px;
}
</style>
</head>
<h1> ads for approval: ' . $numrow . ' </h1>
('.$string.') ');
print_r($result);
echo('
<br><br>
');
while ($result=mysql_fetch_array($query)) {
echo ('
<table width="35%">
<tr>
<td width="20%"><p>user: </p>' . $result['username'] . ' </td>
<td width="20%"><p>club: </p>' . $result['club'] . ' </td>
<td width="20%"><p>city: </p>' . $result['city'] . ' </td>
<td width="20%"><p>night: </p>'. $result['night'] . ' </td>
<td width="20%"> <a href="home.php"> Approve</a> </td>
</tr>
</table>
<hr>
');
}
echo ('
<a href="http://www.down2party.com/Nathan/home_page/loginpage.php">Return to home</a>
</html>');
} else {echo ('you are not authorised');}
?>