PHP - Not Pulling Data From Table, Just Field Names
Okay, so I'm trying to run a query to pull the information from a specific item that they click on in order to edit it.
When I run an echo $query, though, it shows the field names rather than the information from the table. How can I make it so that it pulls the information rather than the field names? Here's what I have... <?php include("lib.php"); define("PAGENAME", "Edit Equipment"); if ($player->access < 100) $msg1 = "<font color=\"red\">"; //name error? $error = 0; $query = $db->execute("SELECT * FROM items WHERE id=?", array($_POST['id'])); echo "$id"; $result = mysql_query($query); echo "$query"; $data = mysql_fetch_assoc($result); $msg1 .= "</font>"; //name error? ?> Thanks!! Similar TutorialsI would like to echo field names in my table on webpage one by one. I know mySQL has "describe" function which will list the complete table, I am looking for a way to display each field name one by one with other stuff in between them like input field or description. Hello,
I'm not sure if I'm allowed to post the code, as I didn't write it. But, if you could offer some ideas on where I'm going wrong, I'd be very appreciative!
I basically have a feature on my homepage that displays "Hello _username_!" upon login, but the username is missing. So, I'm presuming that the functionality for pulling the username from the table is somehow failing.
Any ideas?
Thanks
Daisy
http://www.sambob.info/phpfreaks/table.htm the above link is an example of an html table i am trying to pull data out of i need help on starting a code the will pull that first and last name out of that table so in this case i need it to pull out John doe does any one have any idea on how to do this thank you for your help Bob Newbie here, I am actually a math teacher working on creating a simulated store front for my students where they keep up with inventory, budgeting etc. Everyday my students will have to look at how much product is in stock, how much product was sold, and then input how much should be ordered for the next day. I am working on an answer key that will be used to validate students input but the 'quantity' and 'sold' fields will be relative to the most recent post. Right now the code below pulls all the rows under 'quantity', but I need it to only pull the most recent post. I have done my best to search the forum and try to find how to do this, but admittedly I am not even really sure what to be searching for. Any help would be great. Code: [Select] <?php $con = mysql_connect("localhost","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myDatabase", $con); $result = mysql_query("SELECT * FROM myTable"); while($row = mysql_fetch_array($result)) { $quantity = $row['quantity']; $sold = $row['numbersold']; $needed = $row['remaining']; echo $needed-($quantity-$sold); } mysql_close($con); ?> Hello: I have a DB table with this structu Code: [Select] CREATE TABLE `gallery_category` ( `category_id` bigint(20) unsigned NOT NULL auto_increment, `category_name` varchar(50) NOT NULL default '0', PRIMARY KEY (`category_id`), KEY `category_id` (`category_id`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; What I am trying to do id pull this data into my "Edit Product" page and populate a SELECT menu with it. I want the user to be able to re-assign a product to a new category if they chose to do so. I want to add the data (and update the DB) to this area: Code: [Select] <div style="float: left; width: 550px;"> <select name='category_name'> <option></option> </select> </div> This is the full page code that allows users to update product info: Code: [Select] <?php include('../include/myConn.php'); include('../include/myCodeLib.php'); include('include/myCheckLogin.php'); include('include/myAdminNav.php'); include('ckfinder/ckfinder.php'); include('ckeditor/ckeditor.php'); $photo_id = $_REQUEST['photo_id']; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $photo_title = mysql_real_escape_string($_POST['photo_title']); $photo_price = mysql_real_escape_string($_POST['photo_price']); $photo_caption = mysql_real_escape_string($_POST['photo_caption']); $sql = " UPDATE gallery_photos SET photo_title = '$photo_title', photo_price = '$photo_price', photo_caption = '$photo_caption' WHERE photo_id = $photo_id "; mysql_query($sql) && mysql_affected_rows() ?> <?php } $query=mysql_query("SELECT photo_title,photo_price,photo_caption FROM gallery_photos") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $photo_title=$result['photo_title']; $photo_price=$result['photo_price']; $photo_caption=$result['photo_caption']; } ?> <!DOCTYPE HTML> <html> <head> </head> <body> <div id="siteContainer"> <p> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') echo "<span class=\"textError\">". $photo_title ." successfully updated!</span>" ?> </p> <p> <form method="post" action="<?php echo $PHP_SELF;?>"> <input type="hidden" name="POSTBACK" value="EDIT"> <input type='hidden' name='photo_id' value='<?php echo $photo_id; ?>' /> <div style="float: left; width: 120px; margin-right: 30px;"> Category: </div> <div style="float: left; width: 550px;"> <select name='category_name'> <option></option> </select> </div> <div style="float: left; width: 120px; margin-right: 30px;"> Title: </div> <div style="float: left; width: 550px;"> <input type="text" name="photo_title" size="45" maxlength="200" value="<?php echo $photo_title; ?>" /> </div> <div style="clear: both;"><br /></div> <div style="float: left; width: 120px; margin-right: 30px;"> Price: </div> <div style="float: left; width: 550px;"> <input type="text" name="photo_price" size="45" maxlength="200" value="<?php echo $photo_price; ?>" /> </div> <div style="clear: both;"><br /></div> Description:<br /> <textarea cols="107" rows="1" name="photo_caption"><?php echo $photo_caption; ?></textarea> <div style="clear: both;"><br /></div> <br /> <input type="submit" value="Submit" /> </form> </p> </div> </body> </html> How can I do this? I'm stumped ... Thanks! This is my first real jump into PHP, I created a small script a few years ago but have not touched it since (or any other programming for that matter), so I'm not sure how to start this. I need a script that I can run once a day through cron and take the date from one table/filed and insert it into a different table/field, converting the human readable date to a Unix date. Table Name: Ads Field: endtime_value (human readable date) to Table Name: Node Field: auto_expire (Converted to Unix time) Both use a field named "nid" as the key field, so the fields should match each nid field from one table to the next. Following a tutorial I have been able to insert into a field certain data, but I don't know how to do it so the nid's match and how to convert the human readable date to Unix time. Thanks in advance!. Hi all. I've got a little function to generate a simple form depending on the input. What I'd like to do is alias the field names that get output to make them a little more human readable. However, I'm not entirely sure how to do that with the output that I get. The function.... function build_form($table_name){ $result=mysql_query("SELECT * FROM $table_name"); $num=mysql_num_rows($result); $i=1; echo "<table>"; while ($i < mysql_num_fields($result)) { $fields=mysql_fetch_field($result,$i); echo "<tr><td>" . $fields->name . "</td><td><input type=\"text\" size=\"30\" name=\"" . $fields->name . "\" /></td></tr>"; $i++; }; echo "</table>"; }; Q: Where would I have to modify the output from mysql_fetch_field? My modified function... function build_form($table_name){ $result=mysql_query("SELECT * FROM $table_name"); $num=mysql_num_rows($result); $i=1; echo "<table>"; while ($i < mysql_num_fields($result)) { $fields=mysql_fetch_field($result,$i); $field_name=str_replace("_"," ",$fields->name); echo "<tr><td>" . $field_name . "</td><td><input type=\"text\" size=\"30\" name=\"" . $field_name . "\" /></td></tr>"; $i++; }; echo "</table>"; }; Not sure if that will work, but am I heading in the right direction? Any help is much appreciated! Hi. The idea: I want to pull a client record and simply place all the row columns into editable form field text boxes. Once the user reviews and edits a submit button will update the record. What I have: Code: [Select] $Query01 = "SELECT * FROM `CustomerSignups` WHERE `Id` = '$_GET[Id]'"; $Result01 = mysql_query($Query01) or die("Error 01: " . mysql_error()); while ($get_info = mysql_fetch_row($Result01)) { foreach ($get_info as $field) echo "<p>$field</p>"; It displays as expected, a line for each field. How can I get this to pull the field names also and then I can use those as text box input fields...? I need to update a particular table and there be a whole lot of field names. I'd like to do it without having to use them the same way you can access then like $row[12] after a "select" query. The standard for updating (at least how I write it) goes like this ... Code: [Select] $query = "UPDATE linguistics SET welcome1='$var3', welcome2='$var4' WHERE language = '$lengua'"; Well, I'd like to do it where I don't have to name welcome1 and welcome2, but instead refer to their numerical position within the database. On a "select" query we can do this. Can this be done on an update? Something perhaps like ... Code: [Select] $query = "UPDATE linguistics SET 3='$var3', 4='$var4' WHERE language = '$lengua'"; ... where 3 and 4 represent the 4th and 5th fields respectively. I know that this particular phrasing doesn't work because I've tried it, but surely there has to be something. This will save me LOTS of time. Thanks!! I have the following mysql query: Code: [Select] $lead_query=$this->db->query(" SELECT `first_name`, `last_name` , `state` FROM leads WHERE `lead_id`='$lead_id' "); $this->view->lead_query=$lead_query->fetchALL(); Now when I retrieve the above details I need to return the first_name last_name together(separated as space) and the name of the key as client_name in the array. I need it that way because when i return a json_encode($lead_query), I want to return the first_name.last_name as client_name. I currently have php code that outputs information from my database, but how do i make it also display the name of the fields beside each entry of the database? heres my PHP code: Code: [Select] <?php $server = ""; // Enter your MYSQL server name/address between quotes $username = ""; // Your MYSQL username between quotes $password = ""; // Your MYSQL password between quotes $database = ""; // Your MYSQL database between quotes $con = mysql_connect($server, $username, $password); // Connect to the database if(!$con) { die('Could not connect: ' . mysql_error()); } // If connection failed, stop and display error mysql_select_db($database, $con); // Select database to use // Query database $result = mysql_query("SELECT * FROM Properties"); if (!$result) { echo "Error running query:<br>"; trigger_error(mysql_error()); } elseif(!mysql_num_rows($result)) { // no records found by query. echo "No records found"; } else { $i = 0; echo '<div style="font-family:helvetica; font-size:15px; padding-left:15px; padding-top:20px;">'; while($row = mysql_fetch_array($result)) { // Loop through results $i++; echo '<img class="image1" src="'. $row['images'] .'" />'; //image echo "Displaying record $i<br>\n"; echo "<b>" . $row['id'] . "</b><br>\n"; // Where 'id' is the column/field title in the database echo $row['Location'] . "<br>\n"; // Where 'location' is the column/field title in the database echo $row['Property_type'] . "<br>\n"; // as above echo $row['Number_of_bedrooms'] . "<br>\n"; // .. echo $row['Purchase_type'] . "<br>\n"; // .. echo $row['Price_range'] . "<br>\n"; // .. } echo '</div>'; } mysql_close($con); // Close the connection to the database after results, not before. ?> thanks in advance Hi all. The title pretty much says it all. I really have no idea if this is even possible or where to start. A recent dilemma caused me to have to change a field name with some spaces in it. I have a database with ~65 tables, a majority of which were converted from Access. So I'm curious as to how many others have bad field names. Is there a way to use PHP to go through all the field names in a database and remove spaces? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318312.0 Good evening, This has been bugging me for 24 hours now. I have created 2 web applications. The first one is the dummy, and the second one is the final. Basically, this two web applications does the same, just a few modifications made on the final one. I have a process of pulling out of information from the database should the user would want to modify a field. I have a problem though, the dummy one works perfectly, but the new one don't. In fact, if I use the dummy php file together with the new files, the dummy won't be working. But if I use it together with the old files, it works perfectly fine. This is the error I am getting: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\invent-asia\edit_client.php on line 46 <?php include("dbconnection.php"); if(isset($_POST["btnSubmit"])) { $id = $_POST["id"]; $territory = $_POST["territory"]; $job_title = $_POST["job_title"]; $area_of_work = $_POST["area_of_work"]; $employer = $_POST["employer"]; $location = $_POST["location"]; $job_title = $_POST["job_title"]; $date_posted = $_POST["date_posted"]; $closing_date = $_POST["closing_date"]; $department = $_POST["department"]; $gender = $_POST["gender"]; $first_name = $_POST["first_name"]; $last_name = $_POST["last_name"]; $title = $_POST["title"]; $telephone = $_POST["telephone"]; $address_1 = $_POST["address_1"]; $address_2 = $_POST["address_2"]; $address_3 = $_POST["address_3"]; $country = $_POST["country"]; $city = $_POST["city"]; $postal_code = $_POST["postal_code"]; $website = $_POST["website"]; $email_address = $_POST["email_address"]; $comment_by_cg = $_POST["comment_by_cg"]; $date_emailed = $_POST["date_emailed"]; $mailing_comments = $_POST["mailing_comments"]; $telesales_comments = $_POST["telesales_comments"]; $query = "UPDATE contacts SET territory= '".$territory."', job_title = '".$job_title."', area_of_work = '".$area_of_work."', employer = '".$employer."', location = '".$location."', job_title = '".$job_title."', employer = '".$employer."', date_posted = '".$date_posted."', department = '".$department."', closing_date = '".$closing_date."', gender = '".$gender."', first_name = '".$first_name."', last_name = '".$last_name."', title = '".$title."', telephone = '".$telephone."', address_1 = '".$address_1."', address_2 = '".$address_2."', address_3 = '".$address_3."', country = '".$country."', city = '".$city."', postal_code = '".$postal_code."', website = '".$website."', email_address = '".$email_address."', comment_by_cg = '".$comment_by_cg."', date_emailed = '".$date_emailed."', mailing_comments = '".$mailing_comments."', telesales_comments = '".$telesales_comments."' WHERE id = '".$id."'"; mysql_query($query) or die(mysql_error()); echo "<script> alert('You have successfully updated a record'); window.location = 'view.php'; </script>"; } $query = "SELECT * FROM contacts WHERE id = '".$_GET["id"]."'"; $result = mysql_query($query, $connection); if(mysql_num_rows($result) > 0) - THIS IS THE 46th LINE IN THE CODE { $territory = mysql_result($result,0, "territory"); $job_title = mysql_result($result, 0, "job_title"); $area_of_work = mysql_result($result, 0, "area_of_work"); $employer = mysql_result($result, 0, "employer"); $status = mysql_result($result, 0, "status"); $location = mysql_result($result,0, "location"); $department = mysql_result($result,0, "department"); $date_posted = mysql_result($result,0, "date_posted"); $closing_date = mysql_result($result,0, "closing_date"); $gender = mysql_result($result,0, "gender"); $first_name = mysql_result($result,0, "first_name"); $last_name = mysql_result($result,0, "last_name"); $title = mysql_result($result,0, "title"); $telephone = mysql_result($result,0, "telephone"); $address_1 = mysql_result($result,0, "address_1"); $address_2 = mysql_result($result,0, "address_2"); $address_3 = mysql_result($result,0, "address_3"); $city = mysql_result($result,0, "city"); $country = mysql_result($result,0, "country"); $postal_code = mysql_result($result,0, "postal_code"); $website = mysql_result($result,0, "website"); $email_address = mysql_result($result,0, "email_address"); $comment_by_cg = mysql_result($result,0, "comment_by_cg"); $date_emailed = mysql_result($result,0, "date_emailed"); $mailing_comments = mysql_result($result,0, "mailing_comments"); $telesales_comments = mysql_result($result,0, "telesales_comments"); } ?> Can anyone help me solve this issue? This is the only feature in my project that is left bugged Your quick response is well appreciated. Thank you very much Code: [Select] id: 20 Reason: this is a test id: 21 Reason: Tests id: 22 Reason: Lolcatz id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: 36 Reason: Test As you can see on the 2nd code box there are id's 20,21,22 and 36 in the database the rest are not active in the database. i am using using Code: [Select] for to pull out the id that starts with the lowest value in the database, and only have it run until it gets to the maximum value. Code: [Select] for ($id=$set_min; $set_max<=7; $id++) { // $id=$set_min is pulling the smallest value and $set_max is pulling the maximum value so it stops after it gets to 36 $query=mysql_query("SELECT * FROM posted WHERE id = $id"); $query_row=mysql_fetch_array($query); $reason = $query_row[reason]; $pulled_id = $query_row[id]; $pulled_pic22 = $query_row[picture]; $href_pull = "<a href=" . "search.php?id=" . "$id" .">"; echo "<td>" . $href_pull . "<img src=$pulled_pic22 height=200 width=150 />" . "</td>"; } how would i make it so i do not pull the values 23-35 which are not in the active database. Example: http://dev.hackmuch.com/of-the-day/search.php?id=36 FOr some reason i cant pull data from an XML file to insert into the database, it works without error just adds a blank value in the database? i have this code at the moment, i guess arrayValue[71] is the value i need to pull and add to the "TABLE2" table, but when i run the script it just adds a blank value in the database? <?php include "connect.php"; //Price check Isle 9001! Query EVE-Central API. Example XML file is: http://api.eve-central.com/api/marketstat?typeid=35®ionlimit=10000002 $queryItemList = mysql_query("SELECT * FROM TABLE2;") or die(mysql_error()); $rowCount = mysql_num_rows($queryItemList); $s=0; $typeArray = array(); $region = "regionlimit=10000002"; while($s<$rowCount){ $typeID = mysql_result($queryItemList,$s,"typeID"); echo $typeID."<br />"; //echo "start<br />"; $reader = new XMLReader(); //echo "initialized XMLReader<br />"; $url = "http://api.eve-central.com/api/marketstat?typeid=".$typeID; echo $url.$region."<br />"; $reader->open($url.'&'.$region); $t=0; $arrayName = array(); $arrayValue = array(); while ($reader->read()) { //echo $reader->name; $name = $reader->name; $arrayName[$t] = $name; if ($reader->hasValue) { //echo ": " . $reader->value."<br />"; $value = $reader->value; $arrayValue[$t] = $value; } $t++; } echo $arrayValue[71]; $import="UPDATE TABLE2 SET marketPrice='$arrayValue[71]' WHERE typeID='$typeID';"; mysql_query($import) or die(mysql_error()); $s++;; } print_r($typeArray); /*print_r($arrayName); echo "<br />"; echo "<br />"; echo "<br />"; print_r($arrayValue);*/ ?> an example XML file would be: Code: [Select] <!-- Automatically generated data from EVE-Central.com --> <!-- This is the new API :-) --> − <evec_api version="2.0" method="marketstat_xml"> − <marketstat> − <type id="24692"> − <all> <volume>4.00</volume> <avg>152500000.00</avg> <max>152500000.00</max> <min>152500000.00</min> <stddev>0.00</stddev> <median>152500000.00</median> <percentile>0.00</percentile> </all> − <buy> <volume>0.00</volume> <avg>0.00</avg> <max>0.00</max> <min>0.00</min> <stddev>0.00</stddev> <median>0.00</median> <percentile>0.00</percentile> </buy> − <sell> <volume>4.00</volume> <avg>152500000.00</avg> <max>152500000.00</max> <min>152500000.00</min> <stddev>0.00</stddev> <median>152500000.00</median> <percentile>152500000.00</percentile> </sell> </type> </marketstat> </evec_api> im looking at pulling the following value from the <sell> section: Code: [Select] <median>152500000.00</median> i am guessing the above should be arrayValue[71] but for some reason its not picking it up. any help on this would be greatly appreciated as im lost in this script. I am pulling records from a mysql db. Example Output: Team A= Our Team Team b = An opponent team Team A score = 7 Team B score = 8 Team A = Our Team Team b = Another Opponent Team A score = 3 Team B score = 1 What I need now is to add ONE more output, which is whether this is a "WIN" or a "LOSS". Should I add a field into the table that calc's this? If so, how? Please be specific. Or, should I use php to compare Team A score vs Team B score PER every record and then insert this new variable into the output. If so, how do I create a new variable value for every single output in the table? I know ultimately that this is a IF THEN type of calc, but can't quite figure out how specifically. Please be specific. Thanks Hi all, I have the following MySQL insert query: Code: [Select] $insert= mysql_query ("INSERT INTO tablename (column1,`".$EXPfields."`) VALUES ('$something','".$EXPvalues."')"); where $EXPfields is an array of table-field-names and $EXPvalues is an array of table-field-values. Now I want to write an equivalent query, but using UPDATE instead of INSERT INTO, but I don't want to write out all the field names/values separately, but again want to use $EXPfields and $EXPvalues. So something like this: Code: [Select] $update = mysql_query ("UPDATE tablename SET (column1,`".$EXPfields."`) = ('$something','".$EXPvalues."') WHERE .... "); Is this possible? If so, what is the proper syntax? Thanks! Ok I have a fairly straight forward question. I am designing a baseball website and I am trying to add in a schedule, here is what I have: Data Bases 1) Teams DB - Each team has a unique team ID, location, logo, and owner 2) Schedule DB - Each game has a unique game ID, and the schedule is set up like this: AWAY = Team ID, HOME = Team ID.... So I assume I am using the JOIN command to pull the schedule from both databases, any idea how the SQL command would look? |