PHP - Select If Id Exists In Array
hello, have a question. im trying to do a select * where id exists in array $id8
here is my array Code: [Select] $result8 = mysql_query("SELECT * FROM customers WHERE whosclient = 'Lansoft'"); while($row8 = mysql_fetch_array($result8)) { $id8=$row8['id']; } here is my select code. it is only returning results for the highest number in the array Code: [Select] $result = mysql_query("SELECT * FROM timesheets WHERE status = 3 AND billable = 1 AND client = '$id8' ORDER BY date, starttime"); while($row = mysql_fetch_array($result)) { Thanks for any help! Similar TutorialsWell, I made this yesterday then realised, I need to check is it exists... I got this but when I go to accept the application and the member exists in the table it enters it anyway... Code: [Select] <?php $member=$_POST['memberid']; $status=$_POST['Status']; $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a2186214_hbclan",$con); $sql="UPDATE application SET Status = '$status' WHERE ID = '$member'"; $sql1="INSERT INTO table_members(name) SELECT application.Name FROM application WHERE application.ID = '$member'"; if ($status == 'ACCEPTED') { if(mysql_num_rows(mysql_query("SELECT name FROM table_members WHERE name = '$member'"))) { if(mysql_query($sql, $con) or die(mysql_error())) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } else { die('Could not submit: ' . mysql_error()); } } else { if(mysql_query($sql, $con) or die(mysql_error())) { if(mysql_query($sql1, $con) or die(mysql_error())) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } } else { die('Could not submit: ' . mysql_error()); } } } else { if(mysql_query($sql, $con) or die(mysql_error())) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } else { die('Could not submit: ' . mysql_error()); } } mysql_close($con); ?> Maybe I am over thinking this, but I would like to see if their is another value after the current value without moving the internal array pointer. What can I do? Code: [Select] $result = mysql_query("SELECT field_item_id_value FROM `content_type_ads`"); while($row = mysql_fetch_array($result)){ echo $row['field_item_id_value']; echo "<br />"; echo $result; } I am trying to use an "array diff()" argument and I am getting errors with it stating the above is not an array. I have used $row and $result, and neither work. Is this not dumping into an array properly? I am trying to compare an array containing required questions to an array holding survey responses. When a user submits a survey, I take the $_POST array and write the values to a new array called $surveyResponseArray. How can I determine if $surveyResponseArray exists?
Edited February 16 by SaranacLake Hey Guys, I need some assistance, hopefully there is just a simple command that I am not aware of or an easy answer to this. Suppose I have an array with x amount of values... $arr = array("111111" => 10, "222222" => 20); And i have a query.. mysql_query("SELECT * FROM table WHERE table.zip = "111111" "); Suppose I want to modify the query, so it can check if table.zip exists anywhere in $arr, regardless of length of array. And Select the value that the array location refers to. So I need it to check if "111111" is anywhere in the array, and then take the value 10. The example I am applying this to is that I have a database full of business addresses/zip codes and a database full of every zip code in country. So I have a script to get every zip within x miles, and the distance from it, but need to be able to apply it when I query my business addresses to see if it exists within x miles. Thanks! Greg I'm a total noob trying to figure out how to get this function to work right. I want to echo for each Code: [Select] '<OPTION value="'.$SKUCAPS.$skunum.$size.'">'.$size.'</OPTION>' for each size in the $skus[$type][$skunum]['sizes'] array. and if no size exists echo Code: [Select] '<input value="'.$SKUCAPS.$skunum.'" type=hidden" name="item">' Code: [Select] <?php $BANDNAME="Band Name"; $BANDCAPS="BANDNAME"; $BANDLOWER="bandname"; $SKUCAPS="BND"; $SKULOWER="bnd"; $skus = array( 'shirts' => array( '165' => array( 'name' => 'World Khaos Tour <br> Limited Edition Tour Track Jacket.', 'price' => '70.00', 'sizes' => array('M', 'L', '1X' ) ), '139' => array( 'name' => 'KHAOS LEGIONS ALBUM COVER', 'price' => '15.95', 'sizes' => array('S', 'M', 'L', '1X' ) ), ), //end product type 'misc' => array( '603' => array( 'name' => 'Ring Button', 'price' => '3.00', 'sizes' => array('none') ), '602' => array( 'name' => 'Logo Button', 'price' => '3.00', 'sizes' => array('none') ) ) //end product type ); //end skus function makeProduct($type){ global $skus; foreach ( $skus[$type] as $skunum => $value) { $price = $skus[$type][$skunum]['price']; $name = $skus[$type][$skunum]['name']; echo ' <!-- PRODUCT BEGIN --> <li class="product" > <a href="images/'.$SKULOWER.$skunum.'lg.jpg" rel="lightbox"><img src="product_files/'.$SKULOWER.$skunum.'.png"></a><br> <strong>'.$name.'</strong><br>'.$SKUCAPS.$skunum.'<br>$'.$price.'<br> <form name="'.$SKUCAPS.$skunum.'" method="GET" target="_blank" action="http://www.jsrdirect.com/cgi-bin/Make-a-Store.cgi"> <input type="hidden" name="band" value="'.$BANDCAPS.'"> <input type="hidden" name="back" value="http://www.jsrdirect.com/bands/'.$BANDLOWER.'/index.html"> <strong>Qty:</strong> <input type="text" name="quantity" size="1" value="1" > <strong>Size:</strong> <SELECT name="item">'.makeSizes(). '</SELECT> <br><br> <input class="css3button" value="Add To Cart" type="image"> </form> </li> <!-- Product End -->'; } } ?> any help would be greatly appreciated 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";
Hi All, There is a very interesting solved topic here (http://www.phpfreaks.com/forums/index.php?topic=304966.0) about how to access elements in embedded _POST array. But before accessing an element, it might be appropriate to check whether the array it is supposed to be in exists. According to the solution given in the topic indicated above, Code: [Select] $_POST['matType'] is an example of embedded array . Is there a way to check if this array exists? Thanks in advance for your help. In witch conditions you need to transfer the data from a select in array and after that to show from array in content of the page ? Hi guyz, please help me I want to get an id from my database, I use a word to search it which is stored as keys of array. But all the keys can't be found in my database, even though it's there. Here some parts of my code Code: [Select] $arrKeys = array_keys($arrResult); foreach($arrKeys as $key) { //if($arrResult[$key]>1) { echo $key/*."=>". $arrResult[$key]*/."<br>"; //$q = mysql_query("select id_katadasar from tb_katadasar where katadasar='".$key."'"); $kon->query("select id_katadasar from tb_katadasar where katadasar='".$key."'"); var_dump($kon->query); //echo "select id_katadasar from tb_katadasar where katadasar='".$key."'"; //$jum = $kon->getJumlah(); //$row = mysql_fetch_array($q, MYSQL_ASSOC) or die(mysql_error() . ''. $q); //echo count($row); if($row = $kon->tampilkan()) //if($row = mysql_fetch_array($q, MYSQL_NUM)) { //$res = $kon->tampilkan(); echo $row[0]; } //else { //echo "tidak ada di db <br><br>"; } } } $kon->query is equal to mysql_query() $kon->tampilkan return $row=mysql_fetch_array(query) Thanks Is it possible to achieve a similar thing to this... SELECT FROM db WHERE value!=$array My example code is this: $browser_hide = array("1" => "YandexBot 0.0 for unknown"); $query = "SELECT * FROM hitlist_hits WHERE month='$month' AND browser!='$browser_hide' ORDER by id DESC"; Thanks Guys. How can I select a value in an array but not its key. nothing gets put into the select list I have a Prepared Statement that runs a SELECT statement and returns 2 records, and I would like to store the Field Value for each Record into an Array. Here is the code I usually use for queries that return just a single value... // ****************** // Populate Form. * // ****************** // Build query. $q2 = "SELECT response FROM bio_answer WHERE member_id=?"; // Prepare statement. $stmt2 = mysqli_prepare($dbc, $q2); // Bind variable to query. mysqli_stmt_bind_param($stmt2, 'i', $memberID); // Execute query. mysqli_stmt_execute($stmt2); // Store results. mysqli_stmt_store_result($stmt2); // Check # of Records Returned. if (mysqli_stmt_num_rows($stmt2)>0){ // Details Found. // Bind result-set to variable. mysqli_stmt_bind_result($stmt2, $response); // Fetch record. mysqli_stmt_fetch($stmt2); // Close prepared statement. mysqli_stmt_close($stmt2); }else{ // Details Not Found. $_SESSION['resultsCode'] = 'DETAILS_NOT_FOUND_2133'; // Close prepared statement. mysqli_stmt_close($stmt2); // Set Error Source. $_SESSION['errorPage'] = $_SERVER['SCRIPT_NAME']; // Redirect to Display Outcome. header("Location: " . BASE_URL . "/members/results.php"); // End script. exit(); }//End of POPULATE FORM Can someone help me out with the syntax so that I get an end result like this... $answerArray[0] = 'I want to be my own boss!!' $answerArray[1] = 'Don't waste your time trying to do your own Taxes!' Thanks, Debbie hi i have this function for select / function select($table, $rows = '*', $where = null, $group = null, $order = null, $limit = null) this is what i do to display the records. $db->select('loan'); $records = $db->getResult(); foreach($records as $row) { $user = $row['id']; //$name = $row['firstname']; //print_r($row); echo $user; ?> the codes is running.but when i want to use WHERE id = $_POST['id']; this is what im doing. $db->select('member')->where(array('id' => $_POST['client'])); an error as occured where in function where is not existing. please help how to use the proper way of using select * $table where id=$id; in array. thanks Hi I need to do a SELECT query like $query = "SELECT name FROM myusers WHERE myidnum = ".$_SESSION['myid'].""; and put the results into an array like $myusers = array("David","John","Lucy","Sarah"); But I cannot figure out how to do this Can anyone help? Thanks Hi guys, I am getting data from a json source: ``` $jsondata = file_get_contents($url);$response = json_decode($jsondata, true) echo "<pre>"; print_r(array_keys($response));; echo "</pre>"; ``` and this returns: ``` Array ( [0] => jsonapi [1] => data [2] => links ) ``` I want to extract data from specific key in the data array (eg 'title'): ``` [data] => Array ( [0] => Array ( [type] => recipes [id] => d6cd7643-6e44-4d26-9ed9-9da7196cef12 [attributes] => Array ( [internalId] => 7 [isPublished] => 1 [title] => Deep mediterranean quiche [createdAt] => 2019-05-07T13:34:27+0200 [updatedAt] => 2019-05-07T13:34:27+0200 [isPromoted] => 1 [path] => /recipes/deep-mediterranean-quiche [cookingTime] => 30 [difficulty] => medium [ingredients] => Array ( [0] => For the pastry: [1] => 280g plain flour [2] => 140g butter [3] => Cold water [4] => For the filling: [5] => 1 onion [6] => 2 garlic cloves [7] => Half a courgette [8] => 450ml soya milk [9] => 500g grated parmesan [10] => 2 eggs [11] => 200g sun dried tomatoes [12] => 100g feta ) [numberOfservings] => 8 [preparationTime] => 40 [instructions] => ``` How do I loop through the data array and select just the 'title' and 'difficulty' for example? Edited May 12, 2019 by ludo1960I am writing a CRON job that will execute daily. First it will identify from a MySql table the date in a field 'FAPforSale_repost35' If the date is the today date it will then execute commands to delete photo images in a directory, delete the directory, and finally remove the record from the database.
I am on step one which is to build the array of records that match the days date. When I run the code, there are no errors but I am not getting results even though the records in the test table are set for today. Below is the select
<?php define( "DIR", "../zabp_employee_benefits_processor_filesSm/", true ); require( '../zipconfig.php' ); require( DIR . 'lib/db.class.php' ); require_once( $_SERVER['DOCUMENT_ROOT'] . '/_ZABP_merchants/configRecognition.php' ); require_once( $_SERVER['DOCUMENT_ROOT'] . '/_ZABP_merchants/libRecognition/MailClass.inc' ); $todayRepost35 = date("Y-m-d"); echo $todayRepost35; function repostEndSelect() { global $db; $this->db = $db; $data = $this->db->searchQuery( "SELECT `FAPforSale_IDnumber`, `FAPforSale_image1`, `FAPforSale_image2`, `FAPforSale_image3`, `FAPforSale_repost35` FROM `FAP_forSaleTest` Where `FAPforSale_repost35` = '$todayRepost35' "); $this->FAPforSale_IDnumber = $data[0]['FAPforSale_IDnumber']; $this->FAPforSale_image1 = $data[0]['FAPforSale_image1']; $this->FAPforSale_image2 = $data[0]['FAPforSale_image2']; $this->FAPforSale_image3 = $data[0]['FAPforSale_image3']; $this->FAPforSale_repost35 = $data[0]['FAPforSale_repost35']; echo $this->FAPforSale_IDnumber; echo $this->FAPforSale_image1; echo $this->FAPforSale_image2; echo $this->FAPforSale_image3; echo $this->FAPforSale_repost35; } // ends function... echo( ' Finished...' ); ?>Thanks in advance for any suggestions or direction. Chapter two will be when I start testing the commands to delete. Here is my code:
//Grab all the monster in Monster zone 1 $q = $db->query('SELECT * from rpg_monsters where monster_zone = 1'); while ($monsterdata = $db->fetch_assoc($q)) { $monster_chance[] = $monsterdata; }and my var_dump: array (size=4) 0 => array (size=8) 'monster_id' => string '1' (length=1) 'monster_name' => string 'Merman' (length=6) 'monster_level' => string '1' (length=1) 'monster_type' => string 'Normal' (length=6) 'monster_hp' => string '10' (length=2) 'monster_dmg' => string '1' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.10' (length=4) 1 => array (size=8) 'monster_id' => string '2' (length=1) 'monster_name' => string 'Chris Wilson' (length=12) 'monster_level' => string '2' (length=1) 'monster_type' => string 'Unique' (length=6) 'monster_hp' => string '25' (length=2) 'monster_dmg' => string '3' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.04' (length=4) 2 => array (size=8) 'monster_id' => string '3' (length=1) 'monster_name' => string 'Seaman Warrior' (length=14) 'monster_level' => string '2' (length=1) 'monster_type' => string 'Magic' (length=5) 'monster_hp' => string '20' (length=2) 'monster_dmg' => string '2' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.10' (length=4) 3 => array (size=8) 'monster_id' => string '4' (length=1) 'monster_name' => string 'Goblin Attacker' (length=15) 'monster_level' => string '2' (length=1) 'monster_type' => string 'Normal' (length=6) 'monster_hp' => string '15' (length=2) 'monster_dmg' => string '2' (length=1) 'monster_zone' => string '1' (length=1) 'chance' => string '0.10' (length=4)As you can see, the Unique Monster (Chris Wilson) is the lowest chance at only 4%. And all the other mobs at at 10% chance to spawn. Here is my code for probability: $rate = (double) '0.03'; // 3% $max = 1 / $rate; // 100 if (mt_rand(0, $max) === 0) { // chance < $rate echo "Only 3% probability, holy cow!"; }My problem is, I'm a bit lost as how to get my probability code inside a loop and having the dynamic $rate correspond to my "chance" row. Although, I could just use ORDER BY rand() in mysql, it wouldn't let me use any probability and chances... hmmm Edited by Monkuar, 12 October 2014 - 11:12 AM. Hi I am trying to have the following as an example: Code: [Select] <select name="test[]" multiple="multiple">options here</select> <select name="test[]" multiple="multiple">options here</select> Then using $_POST['test'] to grab the boxes in the array. I want to then loop over each box so for example: Code: [Select] $boxes = $_POST['test']; foreach ( $boxes as $box ) // now here i would of expected $box to be an array of the options, } but it's not working like this, all the options from all submitted select boxes come in one array so I cannot distinguish which select box in the array they relate to, is there a way to do this?? |