Jump to content

ririe44

Members
  • Posts

    81
  • Joined

  • Last visited

    Never

Everything posted by ririe44

  1. Or maybe there is a way to say: if $filter_category = "Any Category" then it equals all results/everything...?
  2. K, I solved it, but I'm not totally sure what I did to fix it... I just used another one of my successful attempts and gave it a try... <td width="880"><p><div> <form method="post"> <table align="center"> <tr> <th colspan="3">Product Filter </th> </tr> <? $option_cat = mysql_query("SELECT * FROM `$tbl_name`") or die(mysql_error());?> <? $option_size = mysql_query("SELECT * FROM `$tbl_name`") or die(mysql_error());?> <tr> <td> <select name="filter_category"> <option>Select a Category!</option> <? while($row = mysql_fetch_array($option_cat)){ echo '<option value="'.$row['pd_category'].'">'.$row['pd_category'].'</option>'; } ?> </select> </td> <td> <select name="filter_size"> <option>Select a Size!</option> <? while($row2 = mysql_fetch_array($option_size)){ echo '<option value="'.$row2['pd_size'].'">'.$row2['pd_size'].'</option>'; } ?> </select></td> <td><input type=submit name="submit" value="Go!" /></td> </tr> </table> </form></p> <? if ($_POST['submit']=="Go!") { $filter_category = $_POST['filter_category']; $filter_size = $_POST['filter_size']; $filter_data = mysql_query("SELECT * FROM `$tbl_name` WHERE `pd_category` = '$filter_category' AND `pd_size` = '$filter_size'") or die(mysql_error()); Print "<table border=0 cellpadding=3 width=650 align=center>"; Print "<tr>"; Print "<th> </th> <th>Description</th> <th>Price</th> <th> </th></tr>"; while($filter_info = mysql_fetch_array( $filter_data )) { Print "<tr>"; Print "<td valign='top'>".$filter_info['pd_thumbnail'] . "</td> "; Print "<td valign='top'>".$filter_info['pd_description'] . "</td>"; Print "<td valign='top'>".$filter_info['pd_price'] . "</td>"; Print "<td valign='top'>".$filter_info['pd_btn_link'] . "</td>"; } Print "</table>"; } elseif (isset($_POST['submit'])) { die(mysql_error()); } ?> </td> So, now I would like to add an option "Any Category" and "Any Size" to my two different select tags: <select name="filter_category"> <option>Select a Category!</option> <option value="Any Category">Any Category</option> <? while($row = mysql_fetch_array($option_cat)){ echo '<option value="'.$row['pd_category'].'">'.$row['pd_category'].'</option>'; } ?> </select> </td> <td> <select name="filter_size"> <option>Select a Size!</option> <option value="Any Size">Any Size</option> <? while($row2 = mysql_fetch_array($option_size)){ echo '<option value="'.$row2['pd_size'].'">'.$row2['pd_size'].'</option>'; } ?> </select></td> So, what I'm not sure how to do... is somehow put into my code that if "Any Size" or "Any Category" were selected, then it would bring up all rows of my table as an option... $filter_category = $_POST['filter_category']; $filter_size = $_POST['filter_size']; $filter_data = mysql_query("SELECT * FROM `$tbl_name` WHERE `pd_category` = '$filter_category' AND `pd_size` = '$filter_size'") or die(mysql_error()); So... would something like this work? (well, it doesn't yet, so I need your help) <? if ($_POST['submit']=="Go!") { $filter_category = $_POST['filter_category']; $filter_size = $_POST['filter_size']; if ($filter_category == "Any Category" AND $filter_size =! "Any Size") { $filter_data = mysql_query("SELECT * FROM `$tbl_name` WHERE `pd_size` = '$filter_size'") or die(mysql_error()); } elseif ($filter_category =! "Any Category" AND $filter_size == "Any Size") { $filter_data = mysql_query("SELECT * FROM `$tbl_name` WHERE `pd_category` = '$filter_category'") or die(mysql_error()); } elseif ($filter_category =! "Any Category" AND $filter_size =! "Any Size") { $filter_data = mysql_query("SELECT * FROM `$tbl_name` WHERE `pd_category` = '$filter_category' AND `pd_size` = '$filter_size'") or die(mysql_error()); } elseif ($filter_category == "Any Category" AND $filter_size == "Any Size") { $filter_data = mysql_query("SELECT * FROM `$tbl_name` WHERE `pd_category` = '$filter_category' AND `pd_size` = '$filter_size'") or die(mysql_error()); } Print "<table border=0 cellpadding=3 width=650 align=center>"; Print "<tr>"; Print "<th> </th> <th>Description</th> <th>Price</th> <th> </th></tr>"; while($filter_info = mysql_fetch_array( $filter_data )) { Print "<tr>"; Print "<td valign='top'>".$filter_info['pd_thumbnail'] . "</td> "; Print "<td valign='top'>".$filter_info['pd_description'] . "</td>"; Print "<td valign='top'>".$filter_info['pd_price'] . "</td>"; Print "<td valign='top'>".$filter_info['pd_btn_link'] . "</td>"; } Print "</table>"; } elseif (isset($_POST['submit'])) { die(mysql_error()); } ?> Thanks!
  3. You're right... I had tried it with just `pd_category`, but I hadn't tried it with just `pd_size`, which didn't return anything. So, here's more of my code, because obviously I'm having problems getting the results from `pd_size` (however, my select box does come up with all the options from my table) <? $option_cat = mysql_query("SELECT * FROM `$tbl_name`") or die(mysql_error());?> <? $option_size = mysql_query("SELECT * FROM `$tbl_name`") or die(mysql_error());?> <td><select name="filter_category"> <option>Select a Category!</option> <? while($row=mysql_fetch_array($option_cat)){?> <option value=<?=$row['pd_category']?>><?=$row['pd_category']?></option> <? } ?> </select></td> <td><select name="filter_size"> <option>Select a Size!</option> <? while($row2=mysql_fetch_array($option_size)){?> <option value=<?=$row2['pd_size']?>><?=$row2['pd_size']?></option> <? } ?> </select></td> <td><input type=submit name="submit" value="Go!" /></td> </tr> </table> </form></p> <? if ($_POST['submit']=="Go!") { $filter_category = $_POST['filter_category']; $filter_size = $_POST['filter_size']; $pd_data = mysql_query("SELECT * FROM `$tbl_name` WHERE `pd_category` = '$filter_category' AND `pd_size` = '$filter_size'") or die(mysql_error()); Do you see where my problem is? Thanks for the help!
  4. Hey friends... I'm trying to have multiple filters effect the retrieval from my database. So, for now, I want to be able to retrieve all the rows that have the specified category AND size... $pd_data = mysql_query("SELECT * FROM `$tbl_name` WHERE `pd_category` = '$category' AND `pd_size` = '$size'") or die(mysql_error()); Right now, this is resulting in nothing... is there a better way to do this?
  5. OH YEAH!!!!! Thanks! it's working now, and I'm on my way to victory with your help! Thanks!
  6. could anybody help me with my question as stated above? I guess I'm having a hard time getting the session name equal the value from my table in the 'access' column. Any ideas?
  7. hmm... it didn't return anything... So, in my table I have a column called 'access'... shouldn't this bring up the value for the same user? $sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $access=$result['access'];
  8. it's still not allowing the session to register... I'm directed to my login page every time. Is there a better way to do this: session_start(); if(($_SESSION['rdz_logged'] != 'admin') && ($_SESSION['rdz_logged'] != 'pkg1') && ($_SESSION['rdz_logged'] != 'pkg2') && ($_SESSION['rdz_logged'] != 'pkg3') && ($_SESSION['rdz_logged'] != 'sales')){ header("Location: login.php"); }
  9. So, I have tried it, and it's giving me weird results. My session is registered, but it doesn't give me access like I had hoped. I'm questioning this part... does this make sense to you? $_SESSION["rdz_logged"] = $access; I've changed this code to have quotes... but still not working, any thoughts? session_start(); if(($_SESSION['rdz_logged'] != 'admin') || ($_SESSION['rdz_logged'] != 'pkg1') || ($_SESSION['rdz_logged'] != 'pkg2') || ($_SESSION['rdz_logged'] != 'pkg3') || ($_SESSION['rdz_logged'] != 'sales')){ header("Location: login.php"); }
  10. So, I took a break at this for a bit, but I'm back to solving my situation... So, I need to put together user permissions to certain pages. $sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $access=$result['access']; $count=mysql_num_rows($result); if($count==1){ session_start(); $_SESSION["rdz_logged"] = $access; header("location:../members.php"); } else { echo "<div align=center>The username and password you have provided are incorrect.<br>"; echo 'Return to <a href="../login.php">Login</a></div>'; } session_start(); if(($_SESSION['rdz_logged'] != admin) || ($_SESSION['rdz_logged'] != pkg1) || ($_SESSION['rdz_logged'] != pkg2) || ($_SESSION['rdz_logged'] != pkg3) || ($_SESSION['rdz_logged'] != sales)){ header("Location: login.php"); } So, do you see what I'm trying to do? Should this work?
  11. I am so confused... does anybody have an actual script that I can reference? So I can see how it's done?
  12. So, I'm obviously digging into this a bit... what about making the session name the access level... then I could allow access to pages based on the session name?
  13. Okay, I'm taking a stab at this here... play along with me (I'm very new to this)... checklogin.php $username=$_POST['username']; $password=$_POST['password']; $sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $access=$result['access']; if($access=='admin'){ $perms==6; }elseif($access=='sales'){ $perms==5; }elseif($access=='pkg3'){ $perms==4; }elseif($access=='pkg2'){ $perms==5; }elseif($access=='pkg1'){ $perms==2; } $count=mysql_num_rows($result); if($count==1){ session_start(); $_SESSION["logged"] = 1 + $perms; header("location:../members.php"); } else { $_SESSION["logged"] < 1 | > 7; echo "<div align=center>The username and password you have provided are incorrect.<br>"; echo 'Return to <a href="./login.html">Login</a></div>'; } So, as you can see I'm giving my user access a number level... 6 = admin, 5 = sales, etc. I want my session to equal 1 + the access level ($perms)... which I'll use for my session status to help control access to certain pages... what i'm not sure about is the else part... <1, or >7.... help?
  14. Okay, this will be basic... but at the same time I'm not really sure what to search for. I need to generate user level access controls to my site. My site will have 5 different levels: level1, level2, level3, sales, and admin. I will have 5 pages as well... level1, level2, level3, sales, and admin. The admin user will be able to see all 5 pages. The sales user will only be able to see level1 to sales. The level3 user will be able to see level1-level3... and so on. My user database will have these levels specified. Can you either help guide me towards my solution, or to another post/tutorial that could help me think through this? Thank you!
  15. So, when I echo $webRoot, I get "mrstore/"... which makes sense why everything is so off... I'm guessing it should read the full url for it to work right, right? So, I need $webRoot to equal "http://www.michaelririe.com/mrstore/" Then, in the even of the code above, it would have returned correctly to the login.php file... So, how do I get $webRoot to come through right?
  16. So I'm playing with plaincart... and I'm having a problem with the file path retrieval. Here's the code that is setting the path.... // setting up the web root and server root for // this shopping cart application $thisFile = str_replace('\\', '/', __FILE__); $docRoot = $_SERVER['DOCUMENT_ROOT']; $webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile); $srvRoot = str_replace('library/config.php', '', $thisFile); define('WEB_ROOT', $webRoot); define('SRV_ROOT', $srvRoot); Then, for example, I have this function to check a user: function checkUser() { // if the session id is not set, redirect to login page if (!isset($_SESSION['plaincart_user_id'])) { header('Location: ' . WEB_ROOT . 'admin/login.php'); exit; } So... when testing this, I goto my url: http://www.michaelririe.com/mrstore/admin. This should direct me to the login.php file, but instead it takes me too http://www.michaelririe.com/mrstore/admin/mrstore/admin/login.php. This is happening all through the program with image paths, links, etc. I'm not sure how to fix the Web Root portion so that it all comes up right... any ideas?
  17. So, like this? $query = ("SELECT cat, sub, SUM(amount) FROM entries GROUP BY cat, sub") or die(mysql_error());
  18. but doesn't count just count the rows? So, what about this... $query = ("SELECT 'cat' AND 'sub', SUM(amount) FROM products GROUP BY 'cat' AND 'sub'") or die(mysql_error());
  19. Maybe I should start simpler (for my sake)... Let's say I just want to print all the distinct combinations of 'cat' and 'sub' from 'entries' with their totals.... $entry_data = mysql_query("SELECT SUM(amount) FROM $tbl_name WHERE ?__cat & sub are unique__?) or die(mysql_error()); Print "<th>Category:</th> <th>Sub-Category:</th> <th>Amount:</th></tr>"; while($info_entry = mysql_fetch_array( $entry_data )) { Print "<tr>"; Print "<td>".$info_entry['cat'] . "</td> "; Print "<td>".$info_entry['sub'] . "</td> "; Print "<td>$".$info_entry['amount'] . "</td> "; } Print "</table>";
  20. This is a Mysql query I'm wanting to do... and here's my stab at it, and want to run it by you... I have two tables: entries, and accounts. A column in entries is called "cat", another called "sub", and another called "amount". In the accounts table I have "cat", "sub", and "balance". The accounts table is rows of individual "cat"s and "sub"s that the entries table uses. So, I want to subtract the sum of all "cat"/"sub" from the entries table from the "balance" column in the accounts table. For example in entries there might be: Home - Electricity - $35 .... Home - Electricity - $35 .... etc. I want to subtract $70 (35+35) from the account balance. I only need to run this once, and it seems like a lot of code to do something simple... So, here's my stab at it: $tbl_name = 'accounts'; $tbl_name2 = 'entries'; $sub_sum = mysql_query("SELECT SUM(amount) FROM $tbl_name2 WHERE `cat` = '' AND `sub` = ''") or die(mysql_error()); $sub_fetch = mysql_fetch_assoc($sub_sum); $sub_total = $sub_fetch['SUM(budget)']; mysql_query("UPDATE `accounts` SET `balance` = (`balance`- '$sub_total') WHERE `sub` = '$sub' AND `cat` = '$cat'") or die(mysql_error()); Now I'm not sure if it's even a stab... any help?
  21. ririe44

    Table Math

    So, how would I modify this to do what I want? $query = "INSERT INTO `$tbl_name` (`id`, `period`, `start`, `end`) VALUES ('NULL','".$period."','".$start."','".$end."')"; $add_period_balance = "UPDATE `tbl_name2` SET `balance` = (`balance`+`budget`)"; if (!mysql_query($query)); { echo "1 Period added. Make another entry? <a href='entries.php'>Yes</a>"; } die(mysql_error()); ?>
  22. ririe44

    Table Math

    accounts has the following columns: id, category, sub_category, budget, and balance... for example... id, cat, sub, budget, balance 1, food, groceries, 150, 23 2. home, electricity, 30, 12 etc. I want to insert the new row into table periods, and add the budget amount to balance so it would end up like this... id, cat, sub, budget, balance 1, food, groceries, 150, 173 2. home, electricity, 30, 42 etc.
  23. ririe44

    Table Math

    Okay, let's see... I have an html form called "Add a Period" (basically just to add a pay period into a personal finance workbook)... the form asks for the period title, period start date, and period end date... Period Title: _________ Period Start: __________ Period End: _____________ Submit btn I also have an accounts table, which is basically a budget. Each account, or budget item (such as mortgage, groceries, etc) has a pay period spending limit... the budget. I am calling these budget items accounts because I plan to have the account maintain a balance... So, every new pay period which is started, I want to add the budgeted amount to the account balance... So, let's say groceries budget is $150, and there's an account balance of $23 when I start my new pay period. Once I enter my info into the form above, I hit submit. It send the information to the periods table to generate the new row in periods. Upon submit, I'd also like it to add $150 to the current $23 in the grocery account. So, after I've clicked submit, I should now have a new pay period, and all my accounts (budget items) should have an increase by the budgeted amount. I hope this makes sense now. So, you can see below the $query is inserting a new row into my periods table... and I was hoping to get $add_period_balance to add the budgeted amount to the balance category of my accounts table... $query = "INSERT INTO `$tbl_name` (`id`, `period`, `start`, `end`) VALUES ('NULL','".$period."','".$start."','".$end."')"; $add_period_balance = "UPDATE `tbl_name2` SET `balance` = (`balance`+`budget`)"; if (!mysql_query($query)); { echo "1 Period added. Make another entry? <a href='entries.php'>Yes</a>"; } die(mysql_error()); ?>
  24. ririe44

    Table Math

    I'm inserting a new row into periods, and I'm updating accounts... Basically, when I complete the form to collect the information for a new period, I also need the accounts table to add a value to the account balance for the new period.
×
×
  • 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.