PHP - Problems With Extracting Values From A Row...
I am trying to extract field data from a specific row,
Here is my code: $query = "SELECT * FROM music WHERE title = '%$selected%'"; $musicresult = mysql_query($query) or die ("Couldn't execute query."); $row = mysql_fetch_array($musicresult); /* extract the contents of the row */ Line 98 extract($row); echo $title." "."<BR>"; echo $select."<BR>"; /* set contents of selected to 1 */ $selectval = $select; ++$selectval ; echo $selectval."<BR>"; /* Put the data into the database */ //$query= "UPDATE music SET select=$selectval WHERE title=$selected"; //$result = mysql_query($query) or die ("could not save new data!"); Here is the error message: Warning: extract() [function.extract]: First argument should be an array in /home/content/a/c/k/acksfaq/html/theackshow/THANKYOU.PHP on line 98 The two echo statements that follow line 98 do not generate an output About the only thing that is different with is table compared with a table that this code works with is the fact that this table (music) is not indexed. What the heck am I doing wrong?? Thanks, Ack Similar TutorialsHi all, I hope someone can help me out here as I think I am close but am not sure where to go from here. The problem is: I have a cms where a user can see a list of photos in the gallery. I provide them the ability to select what photos they want to appear on a particular webpage. The problem I have is that the user wants to be able to put the photos in whatever order they choose. So, I have a form (see attached), the html code is: <table width="566px" cellspacing="0" border="0"> <tr> <td width="33%"> <div class="serviceCell"> <input type='checkbox' checked='checked' name='photos[][0]' value='119' /> Bathroom Sin... <img src="./images/help.gif" title="Enter an integer to signify the order in which this image will appear on the webpage." alt="Enter an integer to signify the order in which this image will appear on the webpage."/> <input type="text" size="2" name="photos[][1]" value="0"/> </div> </td> <td width="33%"> <div class="serviceCell"> <input type='checkbox' checked='checked' name='photos[][0]' value='113' /> Courtyard 1 <img src="./images/help.gif" title="Enter an integer to signify the order in which this image will appear on the webpage." alt="Enter an integer to signify the order in which this image will appear on the webpage."/> <input type="text" size="2" name="photos[][1]" value="0"/> </div> </td> <td width="33%"> <div class="serviceCell"> <input type='checkbox' name='photos[][0]' value='114' /> Courtyard 2 <img src="./images/help.gif" title="Enter an integer to signify the order in which this image will appear on the webpage." alt="Enter an integer to signify the order in which this image will appear on the webpage."/> <input type="text" size="2" name="photos[][1]" value=""/> </div> </td> </tr>... Now, lets assume that the user ticked the box next to 'Courtyard 2' and entered an integer '1' in the input box to signify that this image should be displayed 1st on the chosen webpage. These 2 values go into the multidimensional array (photoid, ranking) and are submitted in the form to php in the photos[][] array. But here is where I have the problem. I am trying to extract the values from the array and then do an insert to a table in mysql. My syntax must be wrong somewhere so I am asking anyone to please offer any advice: if (isset($_REQUEST['submitted'])){ $photos = $_REQUEST['photos']; ... if(!empty($photos)){ foreach($photos as $photoID){ $sql = "INSERT IGNORE INTO menuItemPhotos SET photoid='$photoID[0]', menuItemid='$id', ranking='$photoID[1]'"; $ok = @mysql_query($sql); // execute the query } // End of foreach($photos as $photoID){ } // End of if(!empty($photos)){ Thanks Conor [attachment deleted by admin] What I'm trying to do is take two arrays and combine them using array_combine. After they are combined I want to take each key and value pair and use them in a string to build a MySQL query. See below for some pseudo-code =D <?php $fields = array('first_name', 'last_name'); //the fields that will be set with an UPDATE query. $newvals = array('Joe', 'Blow');//The values that will go into $fields $arr = array_combine($fields, $newvals);//Each value now has a key of the field it will update. /** This is where I want to return my SET string with something like 'SET ' . $arr['first_name'] ' = ' . $arr['first_name_value'] ', etc etc. */ There it is, I suppose. Are there any easier ways of doing what I'm trying to accomplish, that is, am I on the right track or just making things harder for myself? Both arrays will have dynamic values throughout my application, so I need to be able to get both each field and value for each query. Any links to some constructs, etc, etc? That's all I really need and I can post the solution when I've figured it out. HI, I am trying to use pagination on the record getting displayed into the table and there's restriction on record that at a time total 15 records can be displayed and others will be displayed by clicking on NEXT (on which i did the following coding). In my SQL query 'where' clause there is select * from db where status = $query Code: [Select] <?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>?id=<?php echo $yes;?>">Next</a> <?php } // Show if not last page ?> The problem that i am facing is when i click on next then the $query gets equal to null which results to showing no record into the table kindly help how can i modify the above code so the previous value present in $query doesn't get NULL by clicking on next and show next 15 records sucessfully??? NOTE: The main purpose of the above mentioned code is to show next 15 records (which works fine if $query != NULL). Hi I am having issues with the following code. I cannot get the table to produce a subtotal multiplying the value of 'ITEMQTY' which is a text field in the form in which the user enters by the 'ITEMPRICE' field which value is located in a text document. <h1>SHOPPING CART</h1><img src="images/cart.png" alt="Cart" width="100" height="100"/> <a href="browse_index.php">CLICK HERE TO CONTINUE SHOPPING</a> <?php if(isset($_POST['submit'])) { $itemname = $_POST['h1']; //echo $_SESSION['itemname'][$itemname]; unset($_SESSION['itemqty'][$itemname]); unset($_SESSION['itemprice'][$itemname]); unset($_SESSION['itemname'][$itemname]); } echo "<br/><br/>"; echo "<table border='8' cellpadding='10' >"; echo "<tr><th>Name</th><th>Quantity</th><th>Price</th><th>Subtotal</th></tr>"; foreach($_SESSION['itemname'] as $key => $value) $subtotal = ($_SESSION['itemprice']*($_SESSION['itemqty']; { echo '<tr> <td>'.$_SESSION['itemname'][$key].'</td> <td><input type="text" name="t1" value='.$_SESSION['itemqty'][$key].'></td> <td>'.$_SESSION['itemprice'][$key].'</td> <td>'.$_SESSION['h2'][$key].'</td> <td><form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete"><input type="hidden" name="h1" value='.$key.'></td> </tr> <tr><form id="t1" method="post" action="summary.php" name="t1"><input type="submit" name="order" value="SUBMIT ORDER"></tr>'; } echo "</table>"; ?> Folks, I want to extract certain portion form URL. Exmaple: Quote http://abc.com/this-is-test.html Output should be Quote this-is-test Another Example Quote http://abc.com/this-is-yet-another-test.html Output should be Quote this-is-yet-another-test I am not sure how it can be done with preg_match() and regex or something like that... Can someone help me with this please? Cheers Natasha I have an RSS feed, with alot of data of lottery numbers. the feed itself is : http://www.alllotto.com/rss/NY/latest.rss The item i am interested in is: Quote <item> <title>Take 5</title> <description>2011-08-27: 4, 10, 16, 17, 31</description> <guid isPermaLink="false">USA-New-York-Take-5-2011-08-27</guid> </item> How could I output those to varibles? thanks Joe hey guys i need to extract all the IP's of a string and loop them for more operations but for some reason i only get the first one <?php $string = '80.37.14.13 80.37.14.14 80.37.14.15'; preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $string, $matches); foreach ($matches as $ip){ echo "$ip<br>"; } ?> The string is not really seperated by spaces ... it can actualy be messy and have ips rapped arround a lot of code. The regex works because i do get the first one ... What did i miss? I'm *attempting* to write a script that will take a paste of data from a user and when it's submitted it will drop certain parts of the data into databases and be available for recall later. I have the MySQL sorta out I think but I can't test until I get this part done. Basically people will paste a copied paste (CTRL A, CTRL C and go to my form and just hit CTRL V). It will contain a bunch of data I want to drop in the database but in different areas, like the following example the items in bold are the items I want to grab. First Name: Lincoln Last Name: Coe Address: 1234 Easy St, Perfectville, PV 00000 Telephone: 0000000000 $example "Q: Example? A:" Let's assume that I'd like to display $example but exclude "Q:" and "A:", how would I do that? HI guys, I'm quite new to php, and I'm really struggling to get this right. I just cant get it to work properly. Im trying to extract email from a list of URLS. I have currently got it to work with 1 URL at a time, but I am needing to as to how I can pass multiple URLS at once, either from a csv or just pasting them into the input. any help would be much appriciated. here is my current code: Quote <?php $the_url = isset($_REQUEST['url']) ? htmlspecialchars($_REQUEST['url']) : ''; ?> <form method="post"> Please enter full URL of the page to parse (including http://):<br /> <textarea name="url" cols="100" rows="10"><?php echo $the_url; ?></textarea> <br /> <input type="submit" value="Get Emails" /> </form> <?php if (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) { // fetch data from specified url $text = file_get_contents($_REQUEST['url']); } elseif (isset($_REQUEST['text']) && !empty($_REQUEST['text'])) { // get text from text area $text = $_REQUEST['text']; } // parse emails if (!empty($text)) { $res = preg_match_all( "/[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i", $text, $matches ); if ($res) { foreach(array_unique($matches[0]) as $email) { echo $email . "<br />"; } } else { echo "No emails found."; } } ?> I usually only do design work, but a client wanted a log in system to his website, so I decided to do it. I set everything up correctly, and users can sign up, login, and log out. However, he wants to be informed when a user logs into his site. So say (user x) wants logs in, my client wants to receive an email with all of (user x)'s account information. How do I pull a row from mysql based on the login information provided? My database is has 7 columns: user, pass, name, address, state, phone, email Hi there I need to extract data from some XML. I have found a few sites that explain that part to me, however there is a section of the data which I need to extract and am not sure how to go about it. Below is an extract of the XML, the section I am trying to extract is highlighted in red (it is essentially a text message being sent I am trying to get the contents of the sms/text message): <usa_smpp_host>THTTP</usa_smpp_host> <short_message>id:660352946 sub:001 dlvrd:001 submit date:1102081032 done date:1102081035 stat:DELIVRD err:000 text:Test SMS message</short_message> <dest_addr_npi>1</dest_addr_npi> Any assistance would be appreciated. Have played around quite a bit but have not managed to figure it out yet. thanks Hey guys i have a array i made and im wanting to grab a random value out of the array. The only way i can see to do this looking at the list of array functions is i need to random a key first? and then return the value assigned to the random key i just generated? I only see a function that lets me do the opposite. array_search() so now that i have generated a random key how do I grab just the value from the array using the random key. or is there a function i can just random value? $explode_names = explode(" ", $planet_names); $random_key_name = (array_rand($explode_names, 1)); echo $random_key_name; so I'm working on this system which requires me to inject anime show names into a DB for an index. I get them in this form: [Kira-Fansub]_HIGHSCHOOL_OF_THE_DEAD_-_04_(BD_1920x1080_x264_AAC) [F0E73009].mkv I need to get it in this form: Highschool Of The Dead sometimes the words are space seperated. the main part is to extract the text in between the ] and ( and with that i mean [stuff]extract this(other stuff) and sometimes it looks like this: [stuff]extract[stuff] I have NO CLUE how to do this preg_match_all doesn't get me any further.. maybe in stages? I've only been studying PHP for a week now and have come across this problem which I'm sure there is a simple answer to, but I just can't figure it out and would appreciate some help. I've spent far too long on this minor issue already! I have a table which contains a list of products, in this case books, which stores the date when each new item is added. I have a query that then searches through this table and extracts the 6 most recent additions. Here is the code I have so far: Code: [Select] $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $title = $row["title"]; $author = $row["author"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamiclist .= //My table showing the products } } else { $dynamicList = "There are currently no Books listed in this store"; } This works well when I need to display the 5 most recent products in a normal table fashion, one below another, on the page. However, I want to display the products in a more personalised order. For example display the newest item in one section of the page and 3rd newest in another. What is the best way to select an individual row from a query? To extract the details of the 2nd newest item to display in the header, for example. Thanks for your help. I have managed to get this to work but it seems like it is a very long and messy solution. I was wondering if anyone had an idea of how this can be done better. I am new to php and don't know a lot. It shows the text between the tags <h1> and </h1> from the content of a different file Basically I had to start the substr() from the fourth position so it would actually skip the "<h1>" being included, and because I started on the fourth postion I then had to finish four places back to skip the "</h1>" being included. Code: [Select] <?php $id = $_GET['id']; $homepage = file_get_contents("./".$id.".php"); $title = stristr($homepage,"<h1>"); $titlepos = strpos($homepage,"</h1>"); $endpos = $titlepos - 4; echo "Title " . substr($title,4,$endpos); ?> I have a string that looks like /index.php?g1=111&g2=222&g3=333. How can I obtain the value of g1 (i.e. 111)? It does not represent the current state of the server thus I cannot just use $_GET. It also is not necessarily the first item. The script below appears to work, however, http://php.net/manua...n.parse-url.php states This function is intended specifically for the purpose of parsing URLs and not URIs. However, to comply with PHP's backwards compatibility requirements it makes an exception for the file:// scheme where triple slashes (file:///...) are allowed. For any other scheme this is invalid. It appears that my string is a URI and not a URL, but I might be wrong. How should this be accomplished <?php $str='/index.php?g1=111&g2=222&g3=333'; $array=parse_url($str); parse_str($array['query'],$get); echo("<p>{$get['g1']}</p>"); ?> Hi! I have .swf files that have images in them. I can view them with swf decompiler on my computer but i need to have this functionality on my website. Is there any way to extract images from .swf file with php? Hi guys, This is my problem: I have a csv file let's say have these values: blue,1,2,3,4 red,8,5,6,7 I need to add thes values into a 2d array to be able to use like this: colors[1][2]=2 colors[2][4]=7 Where my first number is the row and the second number is the value within that row. This is what I got so far <?PHP $i=0; $j=0; $file_handle = fopen("color-list.csv", "r"); while (!feof($file_handle) ) { $colors = fgetcsv($file_handle, 10000); for ($j=0; $j<=4; $j++) { $row[$i][$j]=$colors[$j]; print row[$i][$j]; } $i++; ?> For some reason this doesn't work. Maybe I am declaring the arrays wrong. Thank you! |