PHP - Duplicate Xml Data Returned, How To List Ony Unique Data?
I'm pulling data from an xml file and I'm getting a lot of duplicates. How can I remove the duplicates from the query?
Code: [Select] foreach($xml->category->subcategory as $category){ echo $category[id]; }//end foreach Similar TutorialsHello,
This is confusing me! - this code is finding 2 rows of data ($nrows is 2), but I'm only getting 1 row of data returned. On the second while loop I'm getting the following error message:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/website.com/test.php on line 26
$query ="SELECT * FROM Accounts WHERE (jaaLatitude = '' OR jaaLongitude = '')"; $result=mysql_query($query) or die ("Connection to database table failed." . mysql_error()); $nrows=mysql_num_rows($result); $i = 0; if ($nrows > 0) { while($record = mysql_fetch_array($result, MYSQL_BOTH)) { $jaaIndex = $record[jaaIndex]; $jaaEmail = $record[jaaEmail]; $jaaLocation = $record[jaaLocation]; $jaaLongitude = $record[jaaLongitude]; $jaaLatitude = $record[jaaLatitude]; echo "<br>test jaaEmail is $jaaEmail<br>"; $i = $i + 1; } }As I say the first while loop is working, so I don't see what can be wrong with the qurery (it's not failing). Thanks for your help, S I'm sure this is a simple question, and I'm not a total newbie, but I keep drawing a blank. In accordance with existing specifications, a client has created a PHP page on their web server which responds to a query by returning a small block of XML. I need to use that XML, and I have no problem doing that using XMLReader->open(clientURL). I can call the client's PHP page and get XML back that I can parse and everything is wonderful. Except for one thing: I need to send a product ID when I call the client's PHP page, and I need to send it using the POST method. I guess that means my clean and neat one-step process is going to have to become a two-step process, and I'm going to have to use some other means besides XMLReader->open() to retrieve the XML. Can sombody recommend the best way to do this? I need to send POST data first to get the correct XML response, and then I need to capture the XML in a way that allows me to parse it. Hello all, I'm writing a page with a simple database with a table called recipes in it with a series of recipes (go figure). I want to display a list of the recipe titles in ascending alphabetical order with each title linked to another page that displays all of the information about the recipe. I can't seem to get anything to display though (not even the titles) but I'm not getting any errors returned either. It seems as if there is nothing in the table to display (even though there are 40 records there). Any help would be greatly appreciated. Here is the code I have so far: Code: [Select] <?php $dbhost = 'localhost'; $dbuser = '*****'; $dbpass = '*****'; $dbname = '*******'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to database'); mysql_select_db($dbname) or die('Error selecting the database'); // select data from db to use $result = mysql_query("SELECT * FROM recipes ORDER BY title ASC LIMIT 0,50") or die('mysql_error()'.'Error: ' .mysql_errno() ); //display the data while($row = mysql_fetch_array($result)); { echo"<b><center>Healthy Lifestyle Gourmet Recipes</center></b><br /><br />"; echo "<span class=\"recipelink\"><a href=\"reciperesults.php?id=".$row['id']."\" target=\"_blank\">".$row['title']."</a></span><br/>\n"; } mysql_close(); ?> I starred out the connection variables but, they are all correct in my code (I'm not getting the "or die" errors) Hi... I encountered problem in my query and while loop my data was duplicates when I join 2 tables, because the one field that I need to display is from another table. here is my code: Code: [Select] <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $sql = "SELECT Items FROM bom_items ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ echo "<tr> <td style='border: none;font-weight: bold;'> $row[Items]</td> </tr>"; //$sql = "SELECT SubItems, ItemCode, UoM, Class, Description FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error()); //$sql = "SELECT DISTINCT bs.SubItems, bs.ItemCode, bs.UoM, bs.Class, bs.Description,w.BINLocation FROM bom_subitems bs LEFT JOIN wms w ON bs.Items = w.Items WHERE bs.Items = '$row[Items]' AND w.Items = '$row[Items]' ORDER BY bs.Items, w.Items"or die(mysql_error()); $sql = "SELECT DISTINCT bs.SubItems, bs.ItemCode, bs.UoM, bs.Class, bs.Description,w.BINLocation FROM bom_subitems bs, wms w WHERE bs.Items = '$row[Items]' AND w.Items = '$row[Items]' ORDER BY bs.Items, w.Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ echo "<tr> <td style='border: none;'> </td> <td style='border: none;'> $row_sub[SubItems]</td> <td style='border: none;'> $row_sub[ItemCode]</td> <td> </td> <td style='border: none;' size='3'> $row_sub[UoM]</td> <td style='border: none;'> $row_sub[Class]</td> <td style='border: none;'> $row_sub[Description]</td> <td style='border: none;'> $row_sub[BINLocation]</td> </tr>"; } } ?> I will attach my sample page. Thank you I am trying to write a script that runs through a CSV file and inserts unique values in a mysql database and spits the duplicate out into a new CSV. I can find the duplicates when I load it into an array, but when I insert them into a MySQL database, I cannot determine if they are duplicates. If I use INSERT IGNORE, it will run the whole file, and reject the duplicates. This is fine, except I need to create a file of the duplicate entries. What is the best way to determine if the insert attempt was rejected? I could do a select to see if the row is there, spit it out...insert if not, but I was thinking there should be a way for MySQL to talk back to me to cut the queries in half... Any ideas? Thanks I have data similar to below. I am doing a MySQL query and doing a JOIN based on instructor name. I am echoing classes and linking the instructor name to another page with their BIO. All is working great, however I want to use the ID's for something else. How do I differentiate the ID between the Instructors table and the Classes Table without changing the column name in the database?
For instance, I want to echo the Instructor ID and then echo the Classes ID, but they are both the same column name in the database and since they are joined, how will that work?
Instructors:
ID | Instructor | Title | Bio |
1 | Bob Smith | Chef | bob smith is a chef with... |
2 | Jane Doe | Professor | Jane doe is an instructor that... |
Classes:
ID | Instructor | Class Title | Class Description |
4 | Bob Smith | Baking | this is a baking class where you learn.... |
5 | Jane Doe | Food Safety | Food safety is very important... |
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=327017.0 Hi everyone, im looking for some help if anyone can offer it. I currently run a phpbb Playstation3 gaming forum and was looking for a way to show forum members online status info on a seperate page on my forum. I found some php script that pulls the freinds list data from the URL mentioned in the code, for now it only works on my local host and i get errors when trying to run it from my live server. here is the current code: Code: [Select] <?php error_reporting(E_ALL); libxml_use_internal_errors(true); $fp = fopen("curl_log.txt",'a+'); //Logging purposes only $dataURL = "https://secure.eu.playstation.com/ajax/mypsn/friend/presence"; $loginURL = "https://store.playstation.com/external/login.action?returnURL=https://secure.eu.playstation.com/sign-in/confirmation"; $cc = curl_init(); getData(); function getData() { global $cc,$fp,$dataURL; curl_setopt ($cc, CURLOPT_URL, $dataURL); curl_setopt ($cc, CURLOPT_POST, 0); curl_setopt ($cc, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($cc, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($cc, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7'); curl_setopt ($cc, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($cc, CURLOPT_REFERER, $dataURL); curl_setopt ($cc, CURLOPT_VERBOSE, 1); curl_setopt ($cc, CURLOPT_STDERR, $fp); curl_setopt ($cc, CURLOPT_COOKIEFILE, 'cookie.txt'); $output = curl_exec($cc); $xml = simplexml_load_string($output); if (!$xml) { login(); } else { // Here you will have a simpleXML object that you can do with as you please - example output below. foreach($xml->psn_friend as $friend) { $img_loc = str_replace("//", "/", $friend->current_avatar); echo "<img src=\"https://secure.eu.playstation.com".$img_loc."\"/> "; echo "<font color=\"red\">$friend->onlineid</font> <br />"; echo "Status : ".$friend->current_presence."<BR />"; echo "Game : ".$friend->current_game."<BR />"; echo "Comment : ".$friend->Comment."<BR />"; echo "<BR /><BR />"; } curl_close($cc); fclose($fp); } } function login() { global $cc,$loginURL; curl_setopt ($cc, CURLOPT_URL, $loginURL); curl_setopt ($cc, CURLOPT_POST, 1); curl_setopt ($cc, CURLOPT_POSTFIELDS, 'loginName=<username@user.com>&password=<password>'); curl_setopt ($cc, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_exec($cc); getData(); } ?> The error i mentioned above is related to the Code: [Select] curl_setopt ($cc, CURLOPT_FOLLOWLOCATION command, im not to concerned about that at the moment. Im looking for someone to help me with the actually XML object, its very basic and i would, if poss, love to have it looking like the actual PSN freinds list. Here are images of this codes output and the actuall Freinds list. Codes Ouput: Actuall PSN FR: Would it be possable to actually grab the exact image from the actuall playstation site, as above? or could the online/offline icons be added to the above code with a background image? I hope i have explained the above clearly, if theirs any thing anyone is unsure of please dont hesitate to ask. Hopefully someone can help. Thanks, Lee I am brand new to PHP but, after using W3 Schools, can retrieve a record from a MySQL database using php & SQLi.
I have a page with a list of between 20 and 30 items down one side and a panel on the other. When a user clicks a list item I want to display the details of the clicked item in the panel. The details a Program (text), Convenor (text), Dates (text), Times (Text), Location (text), Notes (Text large).
The details are stored in a MySQL Database 'Documents', in a table 'Programs' and I would like to put the details into text boxes in the panel.
Could you point me to some info on doing this please?
Thanks
please help me the concept or code to retrive data from the database and display data according to the data from the dynamic list box option. Hi? im just a beginner in php i just want to ask how to insert a data into a table from a dropdown list. I have concatenate the itemid and description to form the dropdown list. But when i viewed my item_table the itemid and description columns are null. can you help me with this.. this is my php code for the dropdown list... <?php $query = "SELECT CONCAT(itemid,' ', '-',' ', description) AS Item FROM item_table"; $result = mysql_query($query) or die(mysql_error()); $dropdown = "<SELECT CONCAT(itemid,' ' '-',' ', description) AS Item FROM item_table>"; while($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['Item']}'>{$row['Item']}</option>"; } $dropdown .= "\r\n</select>"; echo $dropdown; ?> this my code for inserting data into the item_table... <?php if(isset($_POST ['submit'])) { $itemid = $_POST['itemid']; $description = $_POST['description']; $datein = $_POST['datein']; $qtyin = $_POST['qtyin']; $unitprice = $_POST['unitprice']; $unit = $_POST['unit']; $category = $_POST['category']; $empid = $_POST['empid']; $message =''; if(($itemid && $description == "")||($itemid && $description == null)) { header("location:IncomingEntry.php?msg=Incorrect"); exit(); } else { $link = mysql_connect('localhost', 'root', '') or die(mysql_error()); $db_selected = mysql_select_db('inventory', $link); $message=''; $query = "INSERT INTO incoming_table (itemid , description, datein, qtyin, unitprice, unit, category, empid) VALUES ('".$itemid."', '".$description."', '".$datein."', '".$qtyin."', '".$unitprice."', '".$unit."', '".$category."', '".$empid."')"; if (!mysql_query($query,$link)) { die('Error: ' . mysql_error()); } header("location: IncomingEntry.php?msg=1 record added"); } } ?> I have a mysql table with the structure of Code: [Select] ID Menu_Name Parent_ID 1 Finance NULL 2 Business NULL 3 Investment 1 4 Trading 2 How can I create a html <ul><li> list based on the parent? I have a form created with code already written. I am in need of a push in the right direction or a potential tutorial on this issue i have. I am running a fanatsy golf website where the user will pick one golfer each week and the cannot select them again. Is there a way I can remove that data from the list for the next week when the user makes his selection or can I have that data another color and unselectable. If you want code, please let me know and i can provide it. Thanks in advance for your help. p.s. the list data is stored in a MySQL database. Hi pals, I got a complex Array from the Query. it's Structure is like Quote Array ( => Array ( [server_name] => anes.admod.net [id] => 1 [server_id] => 1 [description] => nice Anes Server [status] => 0 [max_down_count] => 9 [check_interval] => 15 [fail_recheck] => 6 [log_retain] => 1 [warning] => 12 [critical] => 15 [timeout] => 8 [audible] => Y [email] => Y [im] => Y [sms] => Y [rss] => N [rssid] => [vcare] => Y [created] => 2010-12-06 10:26:26 [last_update] => 2010-12-13 16:41:48 [name] => POP3 [port] => 110 [okay] => OK [warn] => WARNING [crit] => CRITICAL [down] => Connection refused [advanced] => N [typestatus] => 1 ) [1] => Array ( [server_name] => neseema.admod.net [id] => 2 [server_id] => 2 [description] => another server [status] => 1 [max_down_count] => 11 [check_interval] => 15 [fail_recheck] => 12 [log_retain] => 2 [warning] => 12 [critical] => 16 [timeout] => 6 [audible] => Y [email] => Y [im] => Y [sms] => N [rss] => N [rssid] => [vcare] => N [created] => 2010-12-07 10:27:42 [last_update] => 2010-12-13 16:41:48 [name] => Cpanel [port] => 2082 [okay] => OK [warn] => WARNING [crit] => CRITICAL [down] => Connection refused [advanced] => N [typestatus] => 1 ) [2] => Array ( [server_name] => anes.admod.net [id] => 3 [server_id] => 1 [description] => nice Anes Server another Service [status] => 1 [max_down_count] => 14 [check_interval] => 15 [fail_recheck] => 3 [log_retain] => 3 [warning] => 12 [critical] => 16 [timeout] => 18 [audible] => Y [email] => [im] => [sms] => [rss] => N [rssid] => [vcare] => N [created] => 2010-12-07 12:58:01 [last_update] => 2010-12-13 16:41:48 [name] => SMTP [port] => 25 [okay] => OK [warn] => WARNING [crit] => CRITICAL [down] => Connection refused [advanced] => N [typestatus] => 1 ) ) In this Result I have 2 Rows in result to show, I mean I need to merge the data of First (0th) and Third(2nd) element because it display the data of same item. So How it can done, I am working in that whole day but not get a solution fully.... I saw a near solution like : <?php $input = array( 0 => array ( 'id' => 160, 'payment_period' => 'Monthly', 'plan_payment_type_id' => 171, 'payment_type_id' => 4), 1 => Array ( 'id' => 160, 'payment_period' => 'Monthly', 'plan_payment_type_id' => 172, 'payment_type_id' => 5), 2 => Array ( 'id' => 161, 'payment_period' => 'Weekly', 'plan_payment_type_id' => 173, 'payment_type_id' => 9), ); echo "<pre>"; print_r($input); echo "</pre>"; echo "****************************************************************************"; $output = array(); $id_array = array(); $i = 0; foreach($input as $key=>$val) { if(array_key_exists($val['id'],$id_array)) { $pos = $id_array[$val['id']]; $output[$pos]['payment_types'][] = array('plan_payment_type_id'=> $val['plan_payment_type_id'],'payment_type_id' => $val['payment_type_id']); } else { $output[$i] = array('id' => $val['id'],'payment_period' => $val['payment_period'],'payment_types' => array(array('plan_payment_type_id'=> $val['plan_payment_type_id'],'payment_type_id' => $val['payment_type_id']))); $id_array[$val['id']] = $i; $i++; } } echo "<pre>"; print_r($output); echo "</pre>"; ?> But I cannot handle it nicely, please give any sample or helping code idea for same , waiting your immediate Reply Thankfully Anes P.A I am getting an error on line 3 for the original code, so I need help there, but what I do have a question on is this: http://kaboomlabs.com/PDI/test2.php Code: [Select] <?php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) $result = $mysqli_query("SELECT * FROM comp"); echo "<SELECT name='comp'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['name']}</option>\n"; } echo "</select>\n"; $result_close(); ?> What I am attempting to do is two fold. 1. Using PHP create a pull down menu that grabs data from the database. 2. Have something in where after line three there is a dotted break, and then the rest of the list is shown. There are over 150 entities that go into this database, so the top 3 are going to be the most used, the rest are going to be in alphabetical order. Now the database has a auto-increment numbering system, the company name, address, phone number, and email if possible. I only want it to show the company name. Is this possible at all? Hi, I am hoping someone can help me out with a slight issue I have with php and mySQL. I have an ajax-powered form with a select (dropdown) field populated through a php function. Based on the user-selected values in this field, data is displayed on the webpage; i.e. selected value 1 returns values x and y on the page. I am now trying to call additional data (value z) from a different table in the same database, and as before, use the selected values from the dropdown to display the data. For some reason, value z is not changing according to the user-selected value. This is my code: [The function to populate the select field] Code: [Select] function kfl_get_funds_names() { $result = array(); $result['CDF'] = 'Crosby Dragon Fund'; $result['CPF'] = 'Crosby Phoenix Fund'; $result['AMZPIF'] = 'AMZ Plus Income Fund'; $result['KASBIIF'] = 'KASB Islamic Income Opportunity'; $result['KASBCPGF'] = 'KASB Capital Protected Gold Fund'; $result['KASBLF'] = 'KASB Income Opportunity Fund'; $result['KASBCF'] = 'KASB Cash Fund'; $result['KASBBF'] = 'KASB Asset Allocation Fund'; $result['KASBSMF'] = 'KASB Stock Market Fund'; return $result; } [the code calling and using the function to interact with the database] Code: [Select] $funds_to_display = kfl_get_funds_names(); $current_symbol = key( $funds_to_display ); $current_nav_rates = kfl_get_latest_rates( $current_symbol ); [the code calling additional data, value z, from the database, and using the info in the select field to filter it] Code: [Select] $cutoff = kfl_cutoff( $current_symbol ); The display of each of these items is as follows: Code: [Select] <?php echo $current_nav_rates['nav_date']; ?> <?php echo $funds_to_display[$current_symbol]; ?> <?php echo $cutoff['cutoff']; ?> I can't get the $cutoff code to display the correct values. It picks up the first symbol to display and doesn't change with user selection. The code for the selection box, by the way: Code: [Select] <select id="dailynav-funds" autocomplete="off" name="dnf"> <?php foreach ($funds_to_display as $fund_symbol => $fund_name) { echo '<option'; if( $fund_symbol == $current_symbol ) { echo ' selected="selected"'; } echo ' value="' . $fund_symbol . '">'; echo $fund_name; echo '</option>'; } ?> </select> I've tried to get data using $_GET['dnf'] into the cutoff code, but that throws up parse errors. What am I doing wrong, and how can I resolve this issue? Thanks in advance! Hello All,
New Year Greetings!!
I have integrated a script for TODO list in my website. Its working fine, but adding New task will be appear only after refreshing the page, whereas delete and save are happening as and when i click on them. I dont know where can i make it right.
Here is my code
Display
<div class="w-box-content todo-list"> <ul class="todoList"> <?php require "todo.class.php"; $query = mysql_query("SELECT * FROM `tz_todo` ORDER BY `position` ASC"); $todos = array(); while($row = mysql_fetch_assoc($query)){ $todos[] = new ToDo($row); } foreach($todos as $item){ echo $item; } ?> </ul> <a id="addButton" class="green-button" href="#">Add a ToDo</a> <div id="dialog-confirm" title="Delete TODO Item?">Are you sure you want to delete this TODO item?</div>I am including <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/themes/humanity/jquery-ui.css" type="text/css" media="all" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <script type="text/javascript" src="script.js"></script>and in ajax.php require "connect.php"; require "todo.class.php"; $id = (int)$_GET['id']; try{ switch($_GET['action']) { case 'delete': ToDo::delete($id); break; case 'rearrange': ToDo::rearrange($_GET['positions']); break; case 'edit': ToDo::edit($id,$_GET['text']); break; case 'new': ToDo::createNew($_GET['text']); break; } } catch(Exception $e){ // echo $e->getMessage(); die("0"); } echo "1"; Hi guys, basically here pull out the data from database then creating taxt field automatically and submit into anther table. everything works fine but data not inserting in to the table. could you guys check my code please? <?php $con = mysql_connect("localhost","root",""); mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); ?> <?php $result = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name ="cid[]">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['CourseID'] . '">'. $row['CourseID'] .'</option>'; } echo '</select>'; //------------------ ?> <?php if(!empty($_POST["submit"])) { $value = empty($_POST['question']) ? 0 : $_POST['question']; ?> <form name="form1" method="post" action="result.php"> <?php for($i=0;$i<$value;$i++) { echo 'Question NO: <input type="text" name="qno[]" size="2" maxlength="2" class="style10"> Enter Marks: <input type="text" name="marks[]" size="3" maxlength="3" class="style10"><br>'; } ?> <label> <br /> <br /> <input type="submit" name="Submit" value="Submit" class="style10"> </label> </form> <?php } else{ ?> <form method="POST" action="#"> <label> <span class="style10">Enter the Number of Question</span> <input name="question" type="text" class="style10" size="2" maxlength="2"> </label> <input name="submit" type="submit" class="style10" value="Submit"> </form> <?php }?> result.php <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("uni",$con) or die('Could not connect: ' . mysql_error()); foreach ($_POST['cid'] as $c) {$cid [] = $c;} foreach($_POST['qno'] as $q){$qno[] = $q;} foreach($_POST['marks'] as $m){$marks[] = $m;} $ct = 0; for($i=0;$i<count($qno);$i++) { $sql="INSERT INTO examquesion (CourseID,QuesionNo,MarksAllocated) VALUES('$cid[$i]','$qno[$i]','$marks[$i]')"; mysql_query($sql,$con) or die('Error: ' . mysql_error()); $ct++; } echo "$ct record(s) added"; mysql_close($con) ?> could anyone please help me with the code which is i have already displayed data as a multi select list but now i need to select one or more from them and insert into another database table. would be appreciate your help. thanx |