dirt Posted March 27, 2006 Share Posted March 27, 2006 i have this online dvd rental system... i need to make sure the priority is set for every single members level...i have set their priority but i need a output that says "You have rented X amount of DvD's" once the member hits the submit button. Quote Link to comment Share on other sites More sharing options...
shocker-z Posted March 27, 2006 Share Posted March 27, 2006 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 Quote Link to comment Share on other sites More sharing options...
dirt Posted March 28, 2006 Author Share Posted March 28, 2006 but what if i did the codings differently...somethimg like thisif(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... Quote Link to comment Share on other sites More sharing options...
shocker-z Posted March 28, 2006 Share Posted March 28, 2006 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 :) Quote Link to comment Share on other sites More sharing options...
Barand Posted March 28, 2006 Share Posted March 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
dirt Posted March 28, 2006 Author Share Posted March 28, 2006 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'); ?><?phpmysql_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] Quote Link to comment Share on other sites More sharing options...
shocker-z Posted March 28, 2006 Share Posted March 28, 2006 So what is it outputting? and what are you wanting it to output like as we have oviusly got the wrong idea about what you are wanting.. Quote Link to comment Share on other sites More sharing options...
dirt Posted March 28, 2006 Author Share Posted March 28, 2006 i need to get the outcome that says a customer has bought X ammount of DVD either in the same page or diff page.I am reloading to the same page when i click the submit button(but without the outcome) Quote Link to comment Share on other sites More sharing options...
Barand Posted March 28, 2006 Share Posted March 28, 2006 Does $username have a value?If not, before the query[code]$username = $_COOKIE['usrname'];[/code] Quote Link to comment Share on other sites More sharing options...
dirt Posted March 29, 2006 Author Share Posted March 29, 2006 i have tried everything...i still dont know wat to do. [code]<?php require_once('Connections/ren.php'); ?><?phpmysql_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!! Quote Link to comment Share on other sites More sharing options...
shocker-z Posted March 29, 2006 Share Posted March 29, 2006 you have used part my code and part barand'sso your whole code should be[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php require_once('Connections/ren.php'); ?><?phpmysql_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.. Quote Link to comment Share on other sites More sharing options...
dirt Posted March 29, 2006 Author Share Posted March 29, 2006 thanks man for the input. i got it workin...some silly syntax error.it was my fault. Thanks Again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.