Forum Moderators: coopster

Message Too Old, No Replies

Php & Mysql - Picture display

Query display issue...

         

jnscollier

11:18 pm on Jul 17, 2007 (gmt 0)

10+ Year Member



Hey all,
I have two tables. One holds comments and the other holds the question/picture info.

What I want to do is if a logged in user has already commented on a picture, for that picture to not display (there is a drop down that allows them to sort by male/female). And if all the questions in the database are answered for the user to see smthg that says like "no more records". I know this should be so easy for me but i'm having the hardest time with this and i dont know why!

I know none of this is secure either that's my next step once i get the basic functionality going. (i have to do some research and reading on how to prevent injunctions) here's what I have... it still displays all the questions that have already been answered AND not answered by the user.


<?php

$getqry88 = "select distinct(questid) from comments where commid = $id";
$getres88 = mysql_query($getqry88)or die(mysql_error());
$getrows88=mysql_num_rows($getres88);
if($getrows88 > 0){
while($getarray88=mysql_fetch_array($getres88)){

$hqid12 = $getarray88['questid'];

}}

//if male only
if ($_REQUEST['sort'] == 'male')
{

$getqry = "select * from questions where approved = 'yes' and status = 'active' and quest_gender = 'male' and getquest_counter!= $hqid12 order by rand()";

}

//if female only
if ($_REQUEST['sort'] == 'female')
{

$getqry = "select * from questions where approved = 'yes' and status = 'active' and quest_gender = 'female' and getquest_counter!= $hqid12 order by rand()";
}

$getres = mysql_query($getqry)or die(mysql_error());
$getrows=mysql_num_rows($getres);
if($getrows > 0){
while($getarray=mysql_fetch_array($getres)){

$pic = $getarray['pic1'];
$qid2 = $getarray['getquest_counter'];
$question = $getarray['question'];
}
}

else

echo "no records";
?>

I've tried moving the brackets around to include the second query, but that doesn't work either.

any help would be greatly appreciated!

Habtom

5:24 am on Jul 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php
$getqry88 = "SELECT DISTINCT(questid) FROM comments WHERE commid = $id";
$getres88 = mysql_query($getqry88)or die(mysql_error());

while($getarray88 = mysql_fetch_array($getres88)){
$WHERE .= " getquest_counter!=". $getarray88['questid'] ." AND";
}

$WHERE = rtrim($WHERE, "AND");

//if male only
if ($_REQUEST['sort'] == 'male')
{
$getqry = "SELECT * FROM questions WHERE approved = 'yes' AND status = 'active' AND quest_gender = 'male' AND ". $WHERE ." order by rand()";
}

//if female only
if ($_REQUEST['sort'] == 'female')
{
$getqry = "SELECT * FROM questions WHERE approved = 'yes' AND status = 'active' AND quest_gender = 'female' AND ". $WHERE ." order by rand()";
}

$getres = mysql_query($getqry)or die(mysql_error());
$getrows=mysql_num_rows($getres);
if($getrows > 0){
while($getarray=mysql_fetch_array($getres)){
$pic = $getarray['pic1'];
$qid2 = $getarray['getquest_counter'];
$question = $getarray['question'];
}
}
else {
echo "no records";
}
?>

Hope this helps.

Habtom

5:56 am on Jul 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php
$getqry88 = "SELECT DISTINCT(questid) FROM comments WHERE commid = $id";
$getres88 = mysql_query($getqry88)or die(mysql_error());

while($getarray88 = mysql_fetch_array($getres88)){
$WHERE .= " getquest_counter!=". $getarray88['questid'] ." AND";
}

$WHERE = rtrim($WHERE, "AND");
$WHERE = "AND ". $WHERE;
//if male only
if ($_REQUEST['sort'] == 'male')
{
$getqry = "SELECT * FROM questions WHERE approved = 'yes' AND status = 'active' AND quest_gender = 'male' ". $WHERE ." order by rand()";
}

//if female only
if ($_REQUEST['sort'] == 'female')
{
$getqry = "SELECT * FROM questions WHERE approved = 'yes' AND status = 'active' AND quest_gender = 'female' ". $WHERE ." order by rand()";
}

$getres = mysql_query($getqry)or die(mysql_error());
$getrows=mysql_num_rows($getres);
if($getrows > 0){
while($getarray=mysql_fetch_array($getres)){
$pic = $getarray['pic1'];
$qid2 = $getarray['getquest_counter'];
$question = $getarray['question'];
}
}
else {
echo "no records";
}
?>