Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

counting till three

Posted on 2009-04-02
7
Medium Priority
?
304 Views
Last Modified: 2013-12-12
hi
i have the following sql statement it checks whether the code has been used before i wanna make sure that the randomcode is in the table three times
$query = "SELECT * FROM enterused WHERE randomcode='{$_POST['name_full']}'  ";
0
Comment
Question by:mattibutt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:FirestormX
ID: 24050829
I'm not sure I fully understand your question, but it sounds like you want to check how many rows are in the database (to see if there are 3)?
There's a function called mysql_num_rows that you can use.
$query = mysql_query("SELECT * FROM enterused WHERE randomcode='{$_POST['name_full']}'  ");
if (mysql_num_rows($query) == 3)
{Do this}

Open in new window

0
 
LVL 11

Author Comment

by:mattibutt
ID: 24050991
hi
i already got a query not sure how to put 3 value in there
$query = "SELECT * FROM enterused WHERE randomcode='{$_POST['name_full']}'  ";
$ress = mysql_query($query);
if (mysql_num_rows($ress )){
  $access_granted = false;
 $quiz_ready = 'no';
 ($_GET['menu']== 'setup');
}

i have tried the following but it didnt work
$ress = mysql_query($query == 3);

0
 
LVL 11

Author Comment

by:mattibutt
ID: 24051723
hi
i have just realised this the table has duplicate values of the same code so now i wrote the following query but i need to do the condition if the three different unique quizes have used this code then apply the logic below
$query = "SELECT count(distinct quiz)  FROM enterused WHERE randomcode='{$_POST['name_full']}'  ";
$ress = mysql_query($query);
if (mysql_num_rows($ress )){
  $access_granted = false;
 $quiz_ready = 'no';
 ($_GET['menu']== 'setup');
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Accepted Solution

by:
FirestormX earned 1000 total points
ID: 24052410
I'm sorry, I should have explained how the function works a little bit more.
mysql_num_rows() counts the number of rows returned by a query.
So what you're doing, is creating a mysql_query(), and saving it in $ress, and then putting it through mysql_num_rows, which tells you how many rows are in the query. In the example code you gave, it looks like you're saying "if there are rows (any number of rows other than 0)" returned in $ress, then do set access_granted.

I'll do a quick modification to line 3 of your code, and hopefully that'll help with the understanding. =)
$query = "SELECT count(distinct quiz)  FROM enterused WHERE randomcode='{$_POST['name_full']}'  ";
$ress = mysql_query($query);
if (mysql_num_rows($ress ) == 3){
  $access_granted = false;
 $quiz_ready = 'no';
 ($_GET['menu']== 'setup');
}

Open in new window

0
 
LVL 11

Author Comment

by:mattibutt
ID: 24058040
hi FirestormX
i tried your query but its not working i am able to use the code more then three times however i want to stop once three quizes are done using the same code i dont know why its not working thanks for your detailed explanation
0
 
LVL 20

Assisted Solution

by:Gawai
Gawai earned 1000 total points
ID: 24058394
hello mattibutt!

try setting  limit in query

$query = mysql_query("SELECT * FROM enterused WHERE randomcode='{$_POST['name_full']}'  limit 0,3");

0
 
LVL 11

Author Closing Comment

by:mattibutt
ID: 31565831
thanks guys i have sorted out this problem by asking this question differently
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

596 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question