Solved

counting till three

Posted on 2009-04-02
7
290 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Codeigniter Query Help Returning JSON 4 50
What Programs Are Available to Help Map Forms for PDF Creation 11 34
Convert php array to comma seperated list 19 36
JSON decode 5 22
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
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 …

696 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