Solved

counting till three

Posted on 2009-04-02
7
298 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
FirestormX earned 250 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 250 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

724 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