Solved

counting till three

Posted on 2009-04-02
7
258 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
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:FirestormX
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Accepted Solution

by:
FirestormX earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks guys i have sorted out this problem by asking this question differently
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now