Jump to content

Recommended Posts

you would have to have this on another page like on the page that the form submits too but you can just use a query simular to..


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$query=myslq_query("SELECT * FROM table_name WHERE rented_by = '$username'");
$rented=mysql_num_rows($query);
echo("You have rented $rented DVD's");[/quote]


You will need to change table_name to the tablename and also rented_by to the field in your table which store's the username that is currently renting that DVD
but what if i did the codings differently...somethimg like this

if(substr($key,0,3)=="buy"){
query="INSERT INTO buy ( user , movies )VALUES ('".$_COOKIE['usrname']."', '".$val."');"; mysql_query($query, $ren) or die(mysql_error());

where do i put echo("You have rented $ DVD's");??

i dont mind showin the echo output in the same page...
if(substr($key,0,3)=="buy"){
$query="INSERT INTO buy ( user , movies )VALUES ('".$_COOKIE['usrname']."', '".$val."');"; mysql_query($query, $ren) or die(mysql_error());
$query=myslq_query("SELECT * FROM buy WHERE user = '$username'");
$rented=mysql_num_rows($query);
echo("You have rented $rented DVD's");
}

That should work mate :)
The time to execute a query is proportional to the amount of data returned, so selecting data then counting rows is a very inefficient way of getting a count. Using "SELECT * " makes it doubly inefficient.

Use

[code]$query=myslq_query("SELECT COUNT(*) FROM buy WHERE user = '$username'");
$rented=mysql_result($query, 0);
echo("You have rented $rented DVD's");[/code]

This way only a single integer is returned by the query.
i am not getting the output that i want.is there anything i need to add...or mayb i forgot to do something

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php require_once('Connections/ren.php'); ?><?php
mysql_select_db($database_ren, $ren);
$query= "SELECT membership FROM user WHERE username='".$_COOKIE['usrname']."'";
$usr = mysql_query($query, $ren) or die(mysql_error());
$row_usr = mysql_fetch_assoc($usr);
$limit=$row_usr['membership'];

$count=0;
if (isset($_POST['save']) && (isset($_COOKIE['usrname'])) ) {
foreach($_POST as $key => $val){
if(substr($key,0,3)=="buy"){
$query="INSERT INTO buy ( user , movies )VALUES ('".$_COOKIE['usrname']."', '".$val."');";
mysql_query($query, $ren) or die(mysql_error());
$query=myslq_query("SELECT COUNT(*) FROM buy WHERE user = '$username'");
$rented=mysql_result($query, 0);
echo("<center><font color=red>You have rented $rented DVD's </font></center>");[/quote]
i have tried everything...i still dont know wat to do.


[code]<?php require_once('Connections/ren.php'); ?><?php
mysql_select_db($database_ren, $ren);
$query= "SELECT membership FROM user WHERE username='".$_COOKIE['username']."'";
$usr = mysql_query($query, $ren) or die(mysql_error());
$row_usr = mysql_fetch_assoc($usr);
$limit=$row_usr['membership'];

$count=0;
if (isset($_POST['save']) && (isset($_COOKIE['usrname'])) ) {
   foreach($_POST as $key => $val){
         if(substr($key,0,3)=="buy"){
$query="INSERT INTO buy ( user , movies )VALUES ('".$_COOKIE['usrname']."', '".$val."');";
mysql_query($query) or die(mysql_error());
$username = $_COOKIE['usrname'];
$query=mysql_query("SELECT COUNT(*) FROM buy WHERE user = '$username'");
$purchsed=mysql_num_rows($query);
mysql_close();
echo("<center><font color=red>You have purchased $purchased DVD(s) </font></center>");}
    
      }
if($count < $limit){
      if(substr($key,0,4)=="rent"){
$query="INSERT INTO rent ( user , movie )VALUES ('".$_COOKIE['username']."', '".$val."');";      
    mysql_query($query, $ren) or die(mysql_error());
$username = $_COOKIE['usrname'];
$query=mysql_query("SELECT COUNT(*) FROM buy WHERE user = '$username'");
$rented=mysql_num_rows($query);
mysql_close();
echo("<center><font color=red>You have purchased $rented DVD(s) </font></center>");
              }
      }else{
        echo "<center><font color=red>Limit Exceeded!! Only $limit is rented!! </font></center>";
      }
   }
}
if (isset($_POST['save']) && (!isset($_COOKIE['username'])) ) {
   echo "<center><font color=red>Please Login</font></center>";
}

[/code]

and the output is :-

You have purchased DVD's
Limit Exceeded!! Only is rented!!
Limit Exceeded!! Only is rented!!
Limit Exceeded!! Only is rented!!
you have used part my code and part barand's

so your whole code should be

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php require_once('Connections/ren.php'); ?><?php
mysql_select_db($database_ren, $ren);
$query= "SELECT membership FROM user WHERE username='".$_COOKIE['username']."'";
$usr = mysql_query($query, $ren) or die(mysql_error());
$row_usr = mysql_fetch_assoc($usr);
$limit=$row_usr['membership'];

if (isset($_POST['save']) && (isset($_COOKIE['usrname'])) ) {
foreach($_POST as $key => $val){
if(substr($key,0,3)=="buy"){
$query="INSERT INTO buy ( user , movies )VALUES ('".$_COOKIE['usrname']."', '".$val."');";
mysql_query($query) or die(mysql_error());
$username = $_COOKIE['usrname'];
$query=myslq_query("SELECT COUNT(*) FROM buy WHERE user = '$username'");
$count=mysql_result($query, 0);
mysql_close();
echo("<center><font color=red>You have purchased $purchased DVD(s) </font></center>");}

}
if($count < $limit){
if(substr($key,0,4)=="rent"){
$query="INSERT INTO rent ( user , movie )VALUES ('".$_COOKIE['username']."', '".$val."');";
mysql_query($query, $ren) or die(mysql_error());
$username = $_COOKIE['usrname'];
$query=myslq_query("SELECT COUNT(*) FROM buy WHERE user = '$username'");
$rented=mysql_result($query, 0);
mysql_close();
echo("<center><font color=red>You have purchased $rented DVD(s) </font></center>");
}
}else{
echo "<center><font color=red>Limit Exceeded!! Only $limit is rented!! </font></center>";
}
}
}
if (isset($_POST['save']) && (!isset($_COOKIE['username'])) ) {
echo "<center><font color=red>Please Login</font></center>";
}[/quote]

and see how that works :)

i also made your $count an actual count of what they have already purchased as you had set it to 0 which is always less than your limit..
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.