/    Sign up×
Community /Pin to ProfileBookmark

make a correct WHERE clause

[CODE]
<input name=”db” type=”text” readonly=”readonly” value=”<?php echo $_SESSION[‘SESS_USERNAME’] ;?>”>
[/CODE]

From the code above, it will read a username in the database, and then display it in a textbox. I have no problem with this part. Now, i want to make a query that will display all the information from ‘car’ table in the database based on the same username. For example, is my username is ‘[COLOR=”Red”]admin[/COLOR]‘, the table will display all the information about ‘[COLOR=”Red”]admin[/COLOR]‘ user only.This is my code:

[CODE]
$query = “SELECT car.plat, car.cc, car.type, car.trans “.
“FROM car “.
“WHERE car.u_name='[COLOR=”Red”]admin[/COLOR]'”;

$result = mysql_query($query) or die(mysql_error());

echo “<center><table border=’1′>
<tr>
<th>PLAT NUMBER</th>
<th>CAR TYPE</th>
<th>CAR CC</th>
<th>TRANSMISSION</th>

</tr>”;
// Print out the contents of each row into a table
while($row = mysql_fetch_array($result))
{
echo “<tr>”;
echo “<td>” . $row[‘plat’] . “</td>”;
echo “<td>” . $row[‘type’] . “</td>”;
echo “<td>” . $row[‘cc’] . “</td>”;
echo “<td>” . $row[‘trans’] . “</td>”;
echo “</tr>”;
}

$result = mysql_query($query) or die(mysql_error());
echo “</table></center>”;

[/CODE]

::my problem now is, what must i replace in the ‘[COLOR=”Red”]admin[/COLOR]‘ so that all the information that appear just based on the same username.thank you..

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 10.2011 — Do you mean something like this?
[code=php]
$userName = mysql_real_escape_string($_SESSION['SESS_USERNAME']);
$query = "SELECT car.plat, car.cc, car.type, car.trans ".
"FROM car ".
"WHERE car.u_name='$userName'";
[/code]
Copy linkTweet thisAlerts:
@kidphantomauthorApr 11.2011 — yes..thank you soo much
Copy linkTweet thisAlerts:
@kidphantomauthorApr 11.2011 — can i ask 1 more question related to this?
Copy linkTweet thisAlerts:
@kidphantomauthorApr 11.2011 — in the code:
[CODE]
echo "<center><table border='1'>
<tr>
<th>PLAT NUMBER</th>
<th>CAR TYPE</th>
<th>CAR CC</th>
<th>TRANSMISSION</th>


</tr>";
// Print out the contents of each row into a table
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['plat'] . "</td>";
echo "<td>" . $row['type'] . "</td>";
echo "<td>" . $row['cc'] . "</td>";
echo "<td>" . $row['trans'] . "</td>";
echo "</tr>";
}

$result = mysql_query($query) or die(mysql_error());
echo "</table></center>";
[/CODE]

the output will be display in table rite?how can i make it in a drop down list?
×

Success!

Help @kidphantom spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...