PHP - Mysql_num_rows Problem Inside An Array
I have a mysql database table that lists baseball and softball umpires for the season. The table has columns for: date, sport, umpire1, umpire2, umpire3, umpire 4, umpire5, visitor team, and home team.
I'm trying to write a bit of code that will tell me how many times I have schedule (manually) an umpire to see a particular school. Here's what I've come up with. Code: [Select] <?php require_once "/config.php"; $dbc = mysql_pconnect($host, $username, $password); mysql_select_db($db,$dbc); $start_date = '2011-04-01'; $end_date = '2011-06-01'; $umpires = Array('umpire 1 name', 'umpire 1 name', 'umpire 2 name', 'umpire 3 name', 'umpire 4 name', 'umpire 5 name', 'umpire 6 name'); $schools = Array('Bagley', 'Bemidji', 'Blackduck', 'Fosston', 'International Falls', 'Kelliher', 'Laporte', 'Lake of the Woods', 'Remer', 'Walker'); ?> <?php foreach($umpires as $umps) { //selects the first umpire in the array echo "<table width='20%' border ='1'>"; echo "<tr><td>$umps</td><td>Baseball</td><td>Softball</td></tr>"; foreach($schools as $town) { //selects the first town in the array $sql_baseball = "SELECT * FROM $table WHERE (ump1 = $umps OR ump2 = $umps OR ump3 = $umps OR ump4 = $umps OR ump5 = $umps) AND (visitor = $town OR home = $town) AND sport = 'Baseball' AND date >= $start_date AND DATE <= $end_date"; $result_baseball = mysql_query($sql_baseball); $count_baseball=mysql_num_rows($result_baseball); $sql_softball = "SELECT * FROM $table WHERE (ump1 = $umps OR ump2 = $umps OR ump3 = $umps OR ump4 = $umps OR ump5 = $umps) AND (visitor = $town OR home = $town) AND sport = 'Softball' AND date >= $start_date AND DATE <= $end_date"; $result_softball = mysql_query($sql_softball); $count_softball=mysql_num_rows($result_softball); echo "<td>$town</td><td>$count_baseball</td><td>$count_softball</td></tr>"; } //loops the towns echo "</table>"; } //ends each umpire ?> As you can see, I've put all the umpire names in an array...and each school in a separate array. The html tables are being displayed (with the correct names and schools listed...but I'm getting this error: Quote Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /by_school.php on line 33 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /by_school.php on line 37 Line 33 is this - - - $count_baseball=mysql_num_rows($result_baseball); Line 37 is this - - - $count_softball=mysql_num_rows($result_softball); I'm guessing that the problem is that I have multiple selects (one for each town) while using the same variable names for each select...but I can't figure out how to concacate the variable names properly...or even if that's the problem. Any ideas? Thanks! Similar TutorialsThe Script:
$desired_width = 110; if (isset($_POST['submit'])) { $j = 0; //Variable for indexing uploaded image for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded images $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $new_image_name = md5(uniqid()) . "." . $ext[count($ext) - 1]; $target_path = $target_path . $new_image_name;//set the target path with a new name of image $j = $j + 1;//increment the number of uploaded images according to the files in array if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; $tqs = "INSERT INTO images (`original_image_name`, `image_file`, `date_created`) VALUES ('" . $_FILES['file']['name'][$i] . "', '" . $new_image_name . "', now())"; $tqr = mysqli_query($dbc, $tqs); // Select the ID numbers of the last inserted images and store them inside an array. // Use the implode() function on the array to have a string of the ID numbers separated by commas. // Store the ID numbers in the "image_file_id" column of the "thread" table. $tqs = "SELECT `id` FROM `images` WHERE `image_file` IN ('$new_image_name')"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $fetch_array = array(); $row = mysqli_fetch_array($tqr); $fetch_array[] = $row['id']; /* * This prints e.g.: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 ) */ print_r($fetch_array); // Goes over to create the thumbnail images. $src = $target_path; $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/" . $new_image_name; make_thumb($src, $dest, $desired_width); } else {//if file was not moved. echo $j. ').<span id="error">please try again!.</span><br/><br/>'; } } else {//if file size and file type was incorrect. echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; } } }Hey, sorry that I am posting this darn image upload script again, I have this almost finished and I am not looking to ask more questions when it comes to this script specifically. With the script above I have that part where the script should store the ID numbers (the auto_increment column of the table) of the image files inside of one array and then the "implode()" function would get used on the array and then the ID numbers would get inserted into the "image_file_id" column of the "thread" table. As you can see at the above part the script prints the following: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 )And I am looking to insert into the column of the table the following: 542, 543, 544I thought of re-writing the whole image upload script since this happens inside the for loop, though I thought maybe I could be having this done with the script as it is right now. Any suggestions on how to do this? Hi people, My script is for my game, it is to see whether a player has already started a challenge (it is recorded to a table in my database). If the challenge has already been started, then the button to accept the challenge is disabled. But if the challenge hasn't been accepted yet, then the button is clickable. The problem though is the mysql_num_rows function isn't returning 0 like it should (meaning the challenge has not been started) and instead the button is being disabled. Code: [Select] <?php session_start(); include('functions.php'); connect(); ?> <!DOCTYPE html> <html> <head> <title>University Crusade</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen"> <meta name="viewport" content="width=device-width, minimum-scale=1,maximum-scale=1, user-scalable=no"> </head> <body> <?php if (isset($_SESSION['userid'])) { include('safe.php'); ?> <ul id="tab-nav"> <li><a href="stats.php" id="tab-character">Character</a></li> <li><a href="games.php" class="active" id="tab-games">Games</a></li> <li><a href="account.php" id="tab-account">Account</a></li> </ul> <div id="wrapper"> <h2 id="name">Select a Challenge</h2> <ul id="table-view"> <li> <fieldset> <legend>"Easter Egg" Challenge</legend> <div id="rewards"> <p class="instructions"> Find each of the 4 "Easter Egg" barcodes around the university campus. </p> <p> Rewards: Every egg is worth <span class="stat">50</span> XP and <span class="stat">35</span> gold coins. </p> </div> <form action="games.php" method="POST"> <?php $check = mysql_query(" SELECT start1 FROM chal1 WHERE userid='".$_SESSION['userid']."' ") or die ("Could not select database from chal1"); if (mysql_num_rows($check)>0) { echo " <button class=\"buttons\" type=\"submit\" name=\"start1\" disabled=\"disabled\"> Accept challenge </button> "; } else { echo " <button class=\"buttons\" type=\"submit\" name=\"start1\"> Accept challenge </button> "; } ?> </form> </fieldset> </li> <li class="even"> <fieldset> <legend>Increase Strength</legend> <div id="rewards"> <p class="instructions"> You'll find the barcode in the Sports Centre. </p> <p> Rewards: Every time you visit the Sports Centre you'll receive <span class="stat">2</span> Str. points. </p> </div> <form action="games.php" method="POST"> <button class="buttons" type="submit" name="start2"> Accept challenge </button> </form> </fieldset> </li> <li> <fieldset> <legend>Increase Intelligence</legend> <div id="rewards"> <p class="instructions"> You'll find the barcode in the university Library. </p> <p> Rewards: Every time you visit the Library you'll receive <span class="stat">2</span> Int. points. </p> </div> <form action="games.php" method="POST"> <button class="buttons" type="submit" name="start2"> Accept challenge </button> </form> </fieldset> </li> </ul> </div> <div id="footer"> <a class="buttons" href="logout.php">log me out</a> </div> <?php } else { die (" <div id=\"wrapper\"> <p>Opps! You don't seem to be logged in...</p> <a class=\"buttons\" href=\"index.php\">login now</a><br /> <p>Don't have an account? No worries, just <a class=\"buttons\" href=\"register.php\">register for one.</a></p> </div> "); } ?> Anyone know what could be wrong? Thanks I am having real problems getting mysql_num_rows function working with PHP 5 This is the split up script: index.php <?php ini_set('display_errors', 1); require_once 'config.php'; require_once 'func/func.db.php'; $connect = databaseConnect($host, $user, $password, $database); if($connect == true) { // printf("<table>"); // get it querying results for showing users entries as of now: $result = query("SELECT * FROM entries"); if($result == true) { printf("<table> <tr> <td></td> </tr>\n"); while($row = mysql_fetch_array($result)) { printf(" <tr> <td>Result row</td> </tr>\n"); } printf("</table>\n\n"); } // show form for users logged in so they can post entries, ie just one user account for now: require_once 'auth.php'; } ?> func/func.db.php <?php function databaseConnect($host, $user, $password, $database) { $connect = mysql_connect($host, $user, $password); if($connect) { $select_db = mysql_select_db($database, $connect); if($select_db) { return true; } else { return false; } } else { return false; } } function query($sql) { $sql = stripslashes($sql); $query = mysql_real_escape_string($sql); $result = mysql_query($query); if($result){ return $result; } } Then the auth.php, looks like: <?php if(isset($_POST)) { $message = 'Only registered users can post'; if(array_key_exists('submit',$_POST)) { if($_POST['username'] != '' && $_POST['password'] != '') { $username = $_POST['username']; $password = sha1($_POST['password']); // try to log user in: $result = query("SELECT * FROM users WHERE username = '$username' AND '$password'"); echo mysql_num_rows($result); } else { $message = 'You did not enter all required fields, please retry'; } } } else { $message = 'Only registered users can post'; } ?> <p><?=$message;?></p> <table> <form id="login" name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <tr> <td><label for="username">User: </label></td> <td><input type="text" id="username" name="username" value="" /></td> </tr> <tr> <td><label for="password">Password: </label></td> <td><input type="password" id="password" name="password" value="" /></td> </tr> <tr> <td><input type="submit" id="submit" name="submit" value="Login" /></td> </tr> </form> <table> You dont need to know whats in config.php since thats just full of my database connection variables, like the hostname, user, password and database, but its saying mysql_num_rows is an invalid function, since maybe its because its lost connection to the database, but how would I get around this? I thought about maybe making it connect to the database again, but is there any point in doing this? This is the actual error I get: Quote Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/jeremysmith.me.uk/html/blog-dev/auth.php on line 17 Any help is much appreciated, Jez. MYSQL Client server version 5.0.45 Hi All! Got a little irritating problem going on when trying to allow a user to log on with their credentials. I've created the relevant tables, defined connection correctly etc but every time I enter in the correct user account details , it always displays the message I created for when the user account details are wrong. Here is the code: <?php ... ... $find_user_sql = "SELECT `ad_aid`, `ad_aus` FROM `ad_users` WHERE `ad_aus` = '" . $find_user_usr . "' AND `ad_apa` = '" . $find_user_pas . "'"; $find_user_res = mysql_query($find_user_sql); if(mysql_num_rows($find_user_res) > 1|| mysql_num_rows($find_user_res) < 1){ ?> <div id="loginbox"> <div id="loginbox-logo"> </div> <div id="loginbox-content"> <div id="content-error"> <p>The details you entered were incorrect.</p> </div> <form action="login.php" method="post"> <p>Admin Username:<br /> <input type="text" name="ad_user" autocomplete="off" /> </p> <p>Admin Password:<br /> <input type="password" name="ad_pass" autocomplete="off" /> </p> <p> <br /> <input type="submit" name="ad_submit" value="Log me in »" id="login_button" /> </p> </form> </div> <div id="loginbox-bottom"> </div> </div> <?php include_once('includes/footer.php'); $insert_fail_attempt_sql = "INSERT INTO `ad_fail_log` VALUES (NULL, NULL, '" . visitorIP() . "')"; mysql_query($insert_fail_attempt_sql); } else{ include_once('includes/header.php'); $find_user = mysql_fetch_assoc($find_user_res); session_start(); $_SESSION['ad_user'] = $find_user['ad_aus']; $_SESSION['ad_aid'] = $find_user['ad_aid']; ?> <meta http-equiv="refresh" content="3;url=../ad/index.php"> <div id="loginbox"> <div id="loginbox-logo"> </div> <div id="loginbox-content"> <p>Logging In...<br /><br /><br /><br /> <center><img src="images/login-loader.gif" /></center> </p> </div> <div id="loginbox-bottom"> </div> </div> <?php include_once('includes/footer.php'); } } }else{ include_once('includes/header.php'); ?> What the aim of the script is, is to allow users to log in then be taken to a page called index.php . I also have a include php script called check.php (below) which checks users accounts: <?php session_start(); if(!empty($_SESSION['adm_user']) && !empty($_SESSION['adm_aid'])){ $check_user_sql = "SELECT `adm_ana`, `adm_per` FROM `pb_admin_users` WHERE `adm_aus` = '" . $_SESSION['adm_user'] . "' AND `adm_aid` = '" . $_SESSION['adm_aid'] . "'"; $check_user_res = mysql_query($check_user_sql); if(mysql_num_rows($check_user_res) > 1 || mysql_num_rows($check_user_res) < 1)){ $check_user = mysql_fetch_assoc($check_user_res); $_SESSION['adm_name'] = $check_user['adm_ana']; $_SESSION['adm_perm'] = $check_user['adm_per']; }else{ header('Location: https://*website*/' . DIR_ADM . '/login.php'); die($check_user_sql); } }else{ header('Location: https://*website*/' . DIR_ADM . '/login.php'); die($check_user_sql); } ?> I know it's got something to do with the if(mysql_num_rows($find_user_res) > 1|| mysql_num_rows($find_user_res) < 1){ , but I don't know why its rejecting correct username and password . I've tried fiddling around with the mysql_num_rows value to 1 or 0 or ==1 etc but it will only do one of the following: - State that my username and password are incorrect(when they're not) OR - Seem as if it is logging in by displaying "logging in" then for it to only display the login.php page again I would be very grateful if anyone could give me some pointers!! Hi, This is my first post on phpfreaks[dot]com. I want some help on a php code i was writing this night watching a tutorial. Here's the code: if($cat && $name && $desc){ $sql7 = "SELECT * FROM `forum_cats` WHERE `id`='".$cat."'"; $res7 = mysql_query($sql7) or die(mysql_error()); if(mysql_num_rows($res7) == 0){ echo "The forum category you supplied does not exist!\n"; }else{ blablabla... } in cases like this, the mysql_num_rows() function was always working nicely. here for example: $sql3 = "SELECT admin FROM `users` WHERE `id`='".$_SESSION['uid']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); if(mysql_num_rows($res3)==0){ echo "Please login to your account!\n"; }else{ blablabla... } it's working here just fine. i canged my first code into this: if($cat && $name && $desc){ $sql7 = "SELECT * FROM `forum_cats` WHERE `id`='".$cat."'"; $res7 = mysql_query($sql7) or die(mysql_error()); $aaa = mysql_fetch_assoc($res7); if(sizeof($aaa) == 0){ echo "The forum category you supplied does not exist!\n"; }else{ blablabla... } now it works like it is supposed to, but i really want to know what i am doing wrong in the first part. EDIT: I can post a longer code so that maybe there is an error before the script gets to this part. I hope you will understand what i'm talking about Sorry for my English. thanks in advance, Resul. i was wonderin if there is a function where you can get a column in an array format... if there is none, how could I put a row of names inside an array. Code: [Select] @include ("../session.php"); include ("../addons/functions/general.php"); mysql_connect("localhost", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); $result = mysql_query("SELECT friendname FROM friends where username='$session->username'"); while ($row = mysql_fetch_assoc($result)) { } $response = array(); $names = array('ROW of NAMES in HERE); i need $names = array('ROW of Names in Here); to be like this Code: [Select] $names = array('Abraham Lincoln', 'Adolf Hitler', 'Agent Smith', 'Agnus', 'AIAI', 'Akira Shoji', 'Akuma', 'Alex', 'Antoinetta Marie', 'Baal', 'Baby Luigi', 'Backpack', 'Baralai', 'Bardock', 'Baron Mordo', 'Barthello', 'Blanka', 'Bloody Brad', 'Cagnazo', 'Calonord', 'Calypso', 'Cao Cao', 'Captain America', 'Chang', 'Cheato', 'Cheshire Cat', 'Daegon', 'Dampe', 'Daniel Carrington', 'Daniel Lang', 'Dan Severn', 'Darkman', 'Darth Vader', 'Dingodile', 'Dmitri Petrovic', 'Ebonroc', 'Ecco the Dolphin', 'Echidna', 'Edea Kramer', 'Edward van Helgen', 'Elena', 'Eulogy Jones', 'Excella Gionne', 'Ezekial Freeman', 'Fakeman', 'Fasha', 'Fawful', 'Fergie', 'Firebrand', 'Fresh Prince', 'Frylock', 'Fyrus', 'Lamarr', 'Lazarus', 'Lebron James', 'Lee Hong', 'Lemmy Koopa', 'Leon Belmont', 'Lewton', 'Lex Luthor', 'Lighter', 'Lulu'); I want to create a loop foreach [@attributes] I seem to be stuck and cant figure it out. any info would be helpful. Thanks! Code: [Select] Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [ID] => 5760861 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [ID] => 5335615 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [ID] => 6080572 ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [ID] => 5178898 ) ) ) Okay, here is my code, it's messy but i will show u what needs to be done if u can help me Code: [Select] $uservalue=$user['max_stars']; $numCols = 8; $numPerCol = ceil(75 / $numCols); echo "<table class=tuble><tr>"; for($col = 1; $col <= $numCols; $col++) { $numerals = array(1=>'I','II','III','IV','V','VI','VII','VIII'); echo "<td><dl><dt>{$numerals}</dt><dd>"; for($row = 0; $row < $numPerCol; $row++) { $resultRow = 75; if ($i<=$uservalue) { if ($i == $selected) { $checked = 'checked'; }else{ $checked = ''; } echo '<label for="s'.$i.'"><input type="radio" id="s'.$i.'" onclick=\'showPreview('.$i.')\' value="'.$i.'" '.$checked.' name="form[star]"><img src=img/icons/'.$i.'.png></label><br>'; } else { if ($i > 75){ $lol = array("hey","hey2"); foreach ($lol as $lols){ $lol .= $lols; } echo '<font color=#f36f6f><span class=desc><b><img src=img/icons/'.$i.'.png> Confidential</span></b></font><label for="s'.$i.'"><input type="radio" id="s'.$i.'" onclick=\'showPreview('.$i.')\' value="'.$i.'" name="form[star]" disabled></label><img src=img/lock2.png><br>'; }else{ echo '<label for="s'.$i.'"><input type="radio" id="s'.$i.'" onclick=\'showPreview('.$i.')\' value="'.$i.'" name="form[star]" disabled><img src=img/icons/'.$i.'.png></label><img src=img/lock.png><br>'; } } $i++; } echo "</td>"; } This code he Code: [Select] $numerals = array(1=>'I','II','III','IV','V','VI','VII','VIII'); echo "<td><dl><dt>{$numerals}</dt><dd>"; for($row = 0; $row < $numPerCol; $row++) { I need to echo out that $numerals array onto my $numerals variable, but I cant because it's under a for loop, and if i try using a foreach it wont display correctly. because it's already under a forloop Any idea guys? I thought this would be fairly straightforward but for some reason isn't working. I have an array built from some MySQL data: - Code: [Select] $all_products[1] = array( "title"=>"widget", "product_code"=>"wid-123", "colour"=>"blue"); $all_products[2] = array( "title"=>"thingy", "product_code"=>"thi-345", "colour"=>"red"); This works fine when used like: - echo 'Product #1 is a ' . $all_products[1]['colour'] . $all_products[1]['title'] . ', code: ' . $all_products[1]['code']; Gives: "Product #1 is a blue widget, code: wid-123" However, if I do this: - function showproductinfo($thisproduct) { echo 'Product #' . $thisproduct . ' is a ' . $all_products[$thisproduct]['colour'] . $all_products[$thisproduct]['title'] . ', code: ' . $all_products[$thisproduct]['code']; } showproductinfo(1); It gives nothing Can I use a variable passed via a function as the array key in this way? If so, how? And if not, what's the best way to do what I, trying to do? Code: [Select] //this varible contains the array of existing users $existing_users=array('roshan','mike','jason'); //value got from the get metho $user_name=$_POST['user_name']; //checking weather user exists or not in $existing_users array if (in_array($user_name, $existing_users)) { //user name is not available echo "no"; } else { //username available i.e. user name doesn't exists in array echo "yes"; } the array near the top has a list of users, I would like to loop through my users in my database I know how to write a loop but not into here Code: [Select] $existing_users=array('roshan','mike','jason'); My code for replacing user input is as follows: function Replace_BB($text) { $bb = array( '@\[u\](.*?)\[\/u\]@is', '@\[i\](.*?)\[\/i\]@is', '@\[b\](.*?)\[\/b\]@is', '@\[img\](.*?)\[/img\]@is', '@\[url\](.*?)\[/url\]@is', '@\[url=http://(.*?)\](.*?)\[/url\]@is' ); $html = array( '<u>$1</u>', '<em>$1</em>', '<strong>$1</strong>', '<img src="$1" />', '<a href="$1">$1</a>', '<a href="$1">$2</a>' ); return preg_replace($bb, $html, $text); } print_r (Replace_BB($_POST['data'])); How can I use an if statement to decide how to put in my replacement. So for example: Code: [Select] $html = array( 'IF XXXXXX THEN DO THIS>>>>> <u>$1</u> ELSE DO THIS >>>> <u>$1 Error</u>', Hi, Im wondering if there is an easy way to get items out of an array returned by a function inside a class. A code example would be: Code: [Select] class modDB { public function getPwdSalt() { $arr = array("salt", "password"); return $arr; } } ?> And what i would like to be able to do is something like: Code: [Select] $modDB = new modDB; echo $modDB->getPwdSalt()->[1]; and just get returned 'password'. Is something like that possible? Many Thanks. I am echoing a variable that is an array. I want to change the first part of the variable but don't know how to manipulte names inside the ['brackets'] Code: [Select] echo $row['v1_name']);?> lets say I have a value called $var = v1. How do I substitute that like this: Code: [Select] echo $row[$var.'_name']);?> I know the above doesnt work, but thats what i want it to do :-) Hi, The array shown below is causing problems. I know this for sure because when I comment the array out the script runs. Is it: 'pswrd1'=>SHA1('$_POST['pswrd1']') inside the array causing the script not to run?? All help will be greatly appreciated. $register_data = array('username'=>$_POST['username'], 'first_name'=>$_POST['first_name'], 'last_name'=>$_POST['last_name'], 'address'=>$_POST['address'], 'postcode'=>$_POST['postcode'], 'country'=>$_POST['country'], 'e_mail'=>$_POST['e_mail'], 'pswrd1'=>SHA1('$_POST['pswrd1']'), 'phone_no'=>$_POST['phone_no']); I wish to order my results by its occurrence inside the $status array. Basically all of the results with the status 'New' are to be listed first, then the results with the status Today, Tomorrow, Soon and so on. Is this possible, or is there alternatively a different approach to ordering my results how I desire? Code: [Select] $status = array('New', 'Today', 'Tomorrow', 'Soon', 'Future', 'Complete'); $display->get_results("SELECT * FROM todo ORDER by status DESC");
An affiliate marketer refers some products which are stored in a simple array. $all_items_sold = '{"7777":{"item":"hammer","price":"4.99"},"8888":{"item":"nail","price":"1.99"},"9999":{"item":"apple","price":"2.00"}}'; $referred_by_Affiliate = array('1234','8888','7777');
So, out of all the 3 items that sold, only 2 of them were referred by the affiliate marketer.
Currently I do this:
Is there a "best practices" way to accomplish this?
Thank you. I'm wondering if this is at all possible:- Code: [Select] $i = 7; $row_item['comment$i_name'] = "john"; with the $i in $row_item['item$i_id'] being replaced with whatever $i is set as sort of like this:- $row_item['comment.'$i'._name'] Is this sort of concatenation possible inside array element names as I can't seem to get it to work? I tried these below, Code: [Select] class Site extends Controller { function Site() { public $data = Array(); } } but it fail? Thanks in advanced. As the title says, how can i check if multiple arrays exist inside an array or not? Any help is greatly appreciated!
The Script:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <input type="text" name="hashtags" /> <input type="submit" name="submit" /> </form> <?php include("connect.php"); ?> <?php if(isset($_POST['submit'])){ $hashtags = explode(", ", $_POST['hashtags']); for($i= 0; $i < count($hashtags); $i++){ $tqs = "SELECT `id` FROM `hashtags_two` WHERE `hashtags` = '" . $hashtags[$i] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); } $fetch_array = array(); while($row = mysqli_fetch_array($tqr)){ $fetch_array[] = $row['id']; } }Hey, sorry for these fundamental array questions lately, I am not going to ask much more when it comes to this. The hashtags come from the submit form (separated by commas) and get stored inside an array with the "explode()" function. The script should select the ID numbers of the hashtags from the table. With the script above only the last row gets inserted into $fetch_array inside the while loop. When the $fetch_array variable is printed on screen then only one ID number can be seen inside the array: Array ( [0] => 24 )How can I have the other ID numbers too? |