?
Solved

counting till three

Posted on 2009-04-02
7
Medium Priority
?
300 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
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
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

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