PHP - Check If Value In Row Is Equal To Value '1'
hey gys im trying to build a permissions system based on the users group.
Groups can be 1, 2, or 3. Here is the code im using: <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("chat") or die(mysql_error()); $result = mysql_query("SELECT * FROM `members` WHERE username='".$_SESSION['username']."'") or die(mysql_error()); if($result["group"]==1){ echo 'yes'; } else { echo 'no'; } ?> And here is how my db looks like: The thing is, when Im logged in with the user test and run that script, its saying no as the group im in isnt 1. Why is this happening? Can someone help me fix my code. Similar Tutorials.= I am wondering why sometime it is require to add a dot before the equal in php? I'm trying to set up my home page so that when the server loads index.php it that loads home.php but all the information for home.php is stored in the database under ID 13. So how can I say at the top of my home page that if if (!isset($_GET['id'])) { $id == 13; } (this doesn't seem to work) so that all my variables are populated with the information for the home page? Thanks. Hi: I am working with a little bit of code, but not certain if my syntax is correct. Doesn't seem to be doing what I need it to do: Code: [Select] <?php if (date <= "4/8/2011") echo "Event Details"; else echo "Default Text"; ?> Basically, I want to show "Event Details" if the date is before or on 4/8/2011. If it is after 4/8/2011, I want to show "Default Text" It seems to be doing the opposite. What am I missing? I introduce if condition when a string is empty as Code: [Select] if (empty($string)) { How I can add the condition for a certain value too. If empty or equal to "word1". I have put together a new website and I am having a problem that is frustrating me to no end so I am here looking for expert help.
In my "content" column, I am trying to have the article I have written. This content is going to change from page to page depending on the amount of content. At the bottom of the "content" I am trying to add a comments section.
To the right of the "content" column I have a "sidebar" and the problem I am having is as the "content" column grows or shrinks, it is effecting the positioning of the "sidebar" and moves the content of the "sidebar" up or down.
I have tried to investigate how to correct this and what I have read makes absolutely no sense to me so the only way I can figure out to fix this (keeping in mind that I am in the process of teaching myself CSS and I use the trial and error method of learning) is to set the height of the "content" column to a fixed number and then force the "sidebar" to move up or down by using something like 'margin-top: -1200px". The problem with this is when comments are added, the content of the "sidebar" moves down.
My question is, does anyone know of a way to get both columns to adjust to equal heights that won't cause me to pull what little hair I have left out? Would that anyone be willing to explain to me why your method should work?
I know that I should include the code for the page I am having the problem with, but it is (in my opinion) pretty extensive and if someone is willing to try to tackle this it might be easier to just bring up the source code.
Just FYI . . . the page in question can be seen at http://pickmysmoker....ne_smokers.php/
Thanks in advance . . .
is there an easy way to make all variables equal to zero (as opposed to empty) at the end of a loop?
rather than
$a =0;
$b=0;
etc etc
as i have hundreds and hundreds of the things and need to reset them all to equal a value of zero.
thank you in advance.
Hi, i am trying to write a part of script for google shopping export, and all i want is that in this line, everything that is 0 or smaller, the line "pre-order" krijgt and everything that is 1 or greater the line "in stock" This is what i've got now, but it doesn't work I removed the rest of the long code. Code: [Select] $patterns = array(); $patterns[0] = '=<0'; $patterns[1] = '=>1'; $replacements = array(); $replacements[0] = 'vooraf bestellen'; $replacements[1] = 'op voorraad'; if(OPTIONS_TONEN_FEED_AVAILABILITY == 1) $output .= "~" . preg_replace($patterns, $replacements, $row->quantity); how do i make a leaderboard that is capable of handling equal scores from a particular result? we use following points allocations: winner: 5pts second: 3pts third: 2pts fourth: 1pt however, if 2nd and 3rd have tied scores, i would like to combine their point allocations together and divide by 2, i.e. (3+2)/2=2.5points each. initial query for competition ranking: $q_lastcomp = "SELECT p.p_id, p.p_surname, p.p_forename, p.p_handicap, r.r_id, rp.rp_score, rp.rp_handicap, (rp.rp_score-rp.rp_handicap) as net_score "; $q_lastcomp .= "FROM dan_roundplayed rp, dan_round r, dan_player p "; $q_lastcomp .= "WHERE r.r_id = rp.rp_rid "; $q_lastcomp .= "AND p.p_id = rp.rp_pid "; $q_lastcomp .= "AND r.r_id = 6 "; $q_lastcomp .= "ORDER BY net_score"; $r_lastcomp = mysql_query($q_lastcomp) or die(mysql_error()); i then loop through this resultset in this order (top down), and do some more calculations to adjust the players golf handicaps based on these results too. basically, if there are 4 players, the winner has beaten 3 others, second has beaten 2 others, down to last place who has beaten no-one. the number of players you have beaten is multiplied by 10% of their handicap (not precisely this value, but something like it and makes easier to explain), then this adjustment is subtracted from the handicap to make a new handicap for the next comp. this works fine, so long as no-one is tied. but if 2nd and 3rd tie, then both players have effectively only beaten 1 other player (last placed). so i would want both to do "hcap - (1*(hcap*0.1))" for their handicap adjustment calculations. in my current code, even though they were tied, 2nd would have: "hcap - (2*(hcap*0.1))" 3rd would have: "hcap - (1*(hcap*0.1))" my current loop code is: $total_players = mysql_num_rows($r_lastcomp); $i = 1; while($row = mysql_fetch_array($r_lastcomp)){ echo "<br>"; $round_hcap = round($row[p_handicap]); SWITCH ($round_hcap){ CASE $round_hcap >= 0 AND $round_hcap <= 19: $multiplier = 0.1; break; CASE $round_hcap >= 20 AND $round_hcap <= 29: $multiplier = 0.2; break; CASE $round_hcap >= 30 AND $round_hcap <= 39: $multiplier = 0.3; break; CASE $round_hcap >= 40 AND $round_hcap <= 49: $multiplier = 0.4; break; } $hcap_reduce = ($total_players-$i)*$multiplier; $new_hcap = $row[p_handicap]-(($total_players-$i)*$multiplier); $sqlstr = "INSERT INTO dan_handicap VALUES (". $row[p_id]. ",". $row[r_id]. ",". $row[p_handicap]. ",". $i. ","; $sqlstr .= $total_players. ",". $hcap_reduce. ",". $new_hcap. ");"; $sqlstr2 = "UPDATE dan_player SET p_handicap = ". $new_hcap. " WHERE p_id = ". $row[p_id]. ";"; echo $sqlstr. "<br>"; echo $sqlstr2. "<br>"; $i++; } can anyone help with this please? my initial thoughts are i am going to need a drastic adjustment to the initial query add in position number in the comp, i.e. this would produce posn | name | score 1 | winner | 10 2 | tied 2nd | 8 2 | tied 2nd | 8 4 | last place | 5 the second section of code could then use this "position number" for the multiplier part of the calculations. apologies for the length of the post, but this covers the whole requirements. regards jingo_man Problem: I've echoed out all the variables and they all come up and the while loop works too but I want to delete a row from a table where the $session and $row['product_code'] variables match. Result: The row does not get deleted. while ($row = mysql_fetch_array($result)) { if (isset($row['product_code']) > 0) { $ans = $row['quantity'] - $row['qty']; if ($ans<= 0) { $query1 = 'DELETE FROM ecomm_temp_cart WHERE session = "' . $session . ' AND product_code = ' . $row['product_code'] . '"'; mysql_query($query, $db) or (mysql_error($db)); echo 'This ' .$row['product_code'] . ' is sold out.'; } } } Any help appreciated. Code: [Select] function choose_numbers($number,$max) { global $ibforums,$std; srand( (double)microtime() * 1000000 ); $array = array(); $i = 0; while($i!=$number) { $array[] = mt_rand(1,$max); $i++; } $c = count($array); while($c != $number) { $array[] = mt_rand(1,$max); $c = count($array); if($c == $number) { $array = array_unique($array); $c = count($array); } } return $array; } $newnumbers = $this->choose_numbers(3,36); echo "{$newnumbers['0']}|{$newnumbers['1']}|{$newnumbers['2']}"; This echo's out my lottery balls 0|32|22 or technically RANDNuMbER|RANDNUMBER|RANDNUMBER up to 36 is the highest number. Now my issue is, I don't want 2 numbers of the same Value, EVER. Sometimes it does 2|3|2 which is BAD (for my lottery system) is there anyway I can make it so it never will echo out 2 (OR 3) of the same number? Hi Guys what I need to do is display data from two different tables that equal the same value in a specific field Table one has ID Title Course content table two has ID Title Start date End date I need a query that says if title from table one matches title from table 2 then will display the start and end date from table two sorry if this is really simple I am a newbie thanks inadvance Hi guys, Probably going to be a very basic question but i'm lost, i'm trying to figure out how to display an image if the value returned is equal to or greater than a certain number, more of a hypothetical question at the moment, Thanks in advance I'm trying to achieve that my script checks in the database if the user has submitted the data twice. The script takes the user submission and checks it with the column in the database with != and == But it ALWAYS sees it as UNEQUAL even if the data is EQUAL. Here's the script <?php $con_submit = $_POST['submit']; $user_id = $_SESSION['user_id']; if ($con_submit && isset($user_id)){ // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the score data from the POST $knuffix_name = strip_tags(trim($_POST['knuffix_name'])); $knuffix_contribution = $_POST['knuffix_contribution']; $knuffix_category = strip_tags(trim($_POST['sort_category'])); $query = "SELECT contribution FROM con WHERE user_id = '$user_id'"; $query_run = mysqli_query ($dbc, $query) or die (mysqli_error ($dbc)); $assoc = mysqli_fetch_assoc ($query_run) or die (mysqli_error ($dbc)); $db_user_con = $assoc['contribution']; $num_rows = mysqli_num_rows ($query_run) or die (mysqli_erro ($dbc)); if ($knuffix_contribution != $db_user_con) { $query = "SELECT contribution FROM con"; $query_run = mysqli_query ($dbc, $query); $assoc = mysqli_fetch_assoc ($query_run); $db_con = $assoc['contribution']; if ($knuffix_contribution != $db_con) { if (!empty($knuffix_name) && !empty($knuffix_category) && !empty($knuffix_contribution)) { // Write the data into the database $query = sprintf("INSERT INTO con (user_id, name, contribution, category, contributed_date) VALUES ('$user_id', '%s', '%s', '%s', now())", mysqli_real_escape_string($dbc, $knuffix_name), mysqli_real_escape_string($dbc, $knuffix_contribution), mysqli_real_escape_string($dbc, $knuffix_category)); mysqli_query($dbc, $query) or die (mysqli_error($dbc)); mysqli_close($dbc); } else { echo "<p class='error'>Please enter all of the information to add your contribution.</p>"; } } else { echo "You have to be signed-in to do a contribution."; } } else { echo "This contribution already exists in the database. To keep this place clean we do not allow duplicate submissions."; } } else { echo "You cannot make the same submission twice."; } ?> Where is the problem? I'm surely doing something wrong here, but I just cannot see it. Any assistance will be greatly appreciated. In a login script I read the following two variables from an SQL database. Both fields are defined as int. $this->ScheduleA = $rs->fetchCol('ScheduleA'); $this->SchedConst = $rs->fetchCol('SchedConstant'); Later, I retrieve these variables and attempt to compare them. $schA = $sess['ScheduleA']; $schC = $sess['SchedConst']; if ($schA == $schC) { require('Testing.php'); } else { require('NotAllowed.php'); } They never compare as equal, even though they contain the same value. What, pray tell, am I missing? Hi, I am a newbie in PHP (about week and a half). I'm writing a website for myself right now. I've got a problem that I cannot solve. The website is about buying files with website custom balance. What I want to do is disable buy button if user bought this file b4. The is a table user_files that stores user id and file id. And another table that stores files data, ID name who uploaded date time ect.... What I'm trying to do, is disabling buy button if the user has already the file. This is what I've done : while ($row = $rocket->fetch()) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['name']; ?></td> <td><?php echo $row['uploader']; ?></td> <td><?php echo $row['uploadtime']; ?></td> <td><button <?php // Echo "disabled" if $row['id'] id is present in row2['file_id'] <<<<<<< Need to do this in a while. ?> ><a href="download.php?id=<?php echo $row['id']; ?>"></a><?php echo $row['price'] . "D$" ?></button></td> </tr> <?php } ?> What I can't do is check if the file id ($row['id']) is present in ($row2['file_id']), if yes echo "disabled";
Hello,
I am trying to check whether the values in rows are equal or same?
I have two tables orders and line_items. I will store more than 1 line items in line_items table with the same order_id getting from orders table. In line items if i have 3 line items for same order_id, when each line items gets dispatched i will set the status to 'Dispatched' in line_items table. When all the 3 becomes 'Dispatched', i will update the order status as 'Completed' in orders table.
Now i am not getting how to check whether all the 3 line items status id 'Dispatched'.
I tried doing like this
$q1 = "select orders.order_id, orders.item_status as istatus, orders.status as ostatus, orders.authorise, line_items.order_id, line_items.status as bstatus, COUNT(line_items.id) as bid from orders inner join line_items on orders.order_id=line_items.order_id where line_items.order_id=".$id." AND line_items.id<>'Dispatched'"; $q2 = mysql_query($q1); while($q3 = mysql_fetch_array($q2)) { echo $q3['bstatus']; if($q3['bstatus']==''); { echo "HELLLOOOO"; } }But its not working. It goes into if loop even if a single value is 'Dispatched' Please help me. Hi, Actually I am working on text annotation tool, for this I have downloaded from github (https://github.com/ag-sc/SANTO), after ran the code I am getting error while uploading file into tool like Warning*: array_combine(): Both parameters should have an equal number of elements in *C:\xampp\htdocs\SANTO\blocks\importpub.ui.inc.php* on line *141* *Fatal error*: Uncaught mysqli_sql_exception: Column 'Text' cannot be null in C:\xampp\htdocs\SANTO\blocks\importpub.ui.inc.php:145 Stack trace: #0 C:\xampp\htdocs\SANTO\blocks\importpub.ui.inc.php(145): mysqli_stmt->execute() #1 C:\xampp\htdocs\SANTO\index2.php(36): include('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\SANTO\index2.php(54): action_include('importpub.ui') #3 {main} thrown in *C:\xampp\htdocs\SANTO\blocks\importpub.ui.inc.php* on line *145* Please can anyone please help me how to fix this issue, actually they have given readme file I didn't get the solution. Thank you in advance. Here's what I'm wanting to do: Number = 100 In a for loop take that number, 100, and break it down into 5 random numbers to equal 100. So the for loop would output something like this: 1. 32 2. 5 3. 18 4. 9 5. 36 Total = 100 Everytime the numbers would be different. I hope that explains it Thanks! When I run 'select 1700-price as blah from goldclose as t2 order by dayid desc limit 1' by itself in mysql I get a numerical result: one row, one column. In my php script, the 1700 is actually a variable. so here it is $changequery = sprintf("select $goldprice-price as change from goldclose order by dayid desc limit 1"); $change = mysql_query(changequery); while ($row = mysql_fetch_array($change)) { printf("$row[0]"); } mysql_free_result($changeresult); I get the following error, Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 99 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 103 Not sure why? All i want is to get the result of that select statement into a variable such as $change Hi, I'm developing an app using flash AS2 as the front end via PHP and a mySQL database at the backend on my server. what i'm looking to do is update/insert into a table called 'cards' and at the same time update/insert into another table called 'jingle'. There is a field called 'cardID' in jingle that should be the same as the ID number created in 'cards' thus creating a link between entries in the different tables that can be called up as i choose. hope i've been clear i just wouldn't know where to start any help would be appreciated. MySQL client version: 5.0.91 PHPmyAdmin Version information: 3.2.4 thanks in advance |