PHP - Retrieve Results From Mysql As Array And Echo It Out
Hello, im new here, and i have little experience to php and mysql as i started for 2 weeks ago.
I started out with some tutorials and feeling im getting the hang of it. Enough of me, lets get to the point: <?php $con = mysql_connect('localhost',$user,$pass)or die(mysql_error()); $selectdb = mysql_select_db($selectdb)or die(mysql_error()); $sql = "SELECT * From table"; $result = mysql_query($sql); $num = mysql_num_rows($result); $myarray = array($result); $i =0; while ($i < $num){ echo $myarray[$i]; $i++; } ?> Here i have written a dummyscript that does what the original script does, it tries to fetch the keys from the table and then trying to loop it and echo out the results. The output in the browser is this: Resource id #3 I know this probably is a simple fix but i cant seem to get it sorted out. Hope some of you could help me get this baby work, or maybe have another way of doing it more "simple". Thanks in advance! Dan-Levi Similar TutorialsSay I have a table called artists with these fields (artistid, rank).
Then say I have an array called $rankadjustments with a value for each artist (like 1, 7, 3,-3, 5, 9, etc).
I am doing a MYSQL query that gets the info from artists table and sorts according to the rank field like this...
$sql = "SELECT * FROM artists ORDER BY rank";Easy enough. But what if I would like to bring that data back sorted by (rank + rankadjustment). For example, if the artist ranked 1st had a rank of "1" from mysql, but had a rankadjustment of "5" from the rankadjustment array, his "true" rank would be "6". Again, rankadjustment is NOT a field in my table, otherwise it would obviously be simple. It's calculated on the fly and stored in an array. FYI, the array has an index with their "artistid". For example, $rankadjustment[341][8] would be the artist with an artistid of "341" has a rank adjustment of 8. Is there a way to do this IN the query itself? It doesn't seem possible but wanted to find out for sure. If not, what is best way to do? I assume... Get the data sorted JUST by rank and put it all into an array, then create a new array that adds rank to rankadjustment and reorder by the "new" rank amount? I guess that wouldn't be too bad but again, wanted to make sure I'm not missing something that would allow me to do it all in the query (or just more efficiently). Thanks! Edited by galvin, 21 December 2014 - 09:13 PM. Lets start out by saying I'm a nube to sql/php things so I am learning as I go. I try to read all that I can before I post, and only post when I cant figure it out on my own. That being said. What I want to do in simplest terms is be able to assign a variable to each item in an sql table. So say I have an mysql table that has ID, username, fontcolor. I want to be able to pull those out so say.... while($row = mysql_fetch_array($users)) { $username[$i] = $row[username]; $fontcolor[$i] = $row[fontcolor]; } Then on the page I can just call to $username[1] type thing. I have tried mixing this several different ways with for and while and I keep getting errors on the page. I realize the code isn't showing everything but its just there to show you the idea of what I'm trying to do. I just want it to generate a list(array) that will make it easier for me to call back just the items I need on parts of the page with out having to have extra coding everywhere. Thanks in advance. Jim I have spent nearly all day scouring Google for help on this and after trying numerous scripts unsuccessfully and reading up on imap functions but still getting nowhere as well as frying my brain l have had to accept defeat unless anyone of the many gifted coders here can help me out with a script they might have written and used. many thanks Callum I have been given a task, and I gotta say it is kicking my butt.
Here is what I have to do.
1. Have user fill out and submit a form.
2. Data gets sent to: http://www.ffiec.gov...de/Default.aspx
3. Data is set as values for input fields in the sites form.
4. Form executes.
5. Retrieve result data.
6. Display data back to my site.
I have no idea how to do this.
Usually when I have done something like this I use an API.
Hope my question is clear.
Thanks for the help.
I have mysql select query shown below retrieving data from a database:
$sql = " SELECT student, sum( test_score ) as score FROM test INNER JOIN level ON test.level_id = level.level_id GROUP BY student" $result = $mysqli->query($sql, MYSQLI_STORE_RESULT); if($result) { while ($row = $result->fetch_array(MYSQLI_ASSOC)) { var_dump($row); } }On inspection of the retrieved array with var_dump(), i have these result below: array (size=2) 'John' => string 'English' (length=2) 'Score' => string '20' (length=3) array (size=2) 'Mary' => string 'Math' (length=3) 'Score' => string '35' (length=3) array (size=2) 'Samuel' => string 'Physics' (length=3) 'Score' => string '5' (length=3)How do I get at and print out the highest score from this set of array values within this context. I tried this echo max($row['count']) but i understandably got this feedback: Warning: max(): When only one parameter is given, it must be an array Thanks. Code: [Select] if (isset($_POST['update'])) { $signature = $_POST['signature']; $type = $_POST['type']; $name = $_POST['name']; $b=0; While ($b < $i) { echo $signature[$b]."<br>"; echo $type[$b]."<br>"; echo $name[$b]."<br><br>"; $b++; }} I did echo '<pre>'; print_r($_POST); echo '</pre>'; The results are Code: [Select] Array ( [sname] => [notes] => [signature] => Array ( [0] => 1-1 [1] => 1-2 [2] => 1-3 ) [type] => Array ( [0] => Test1 [1] => Test2 [2] => Test3 ) [name] => Array ( [0] => Testa [1] => Testb [2] => Testc ) [update] => Update ) But for some reason nothing is showing up on the screen. How do I present these documentaries like this:
0-9
10 Things You Need to Know About Sleep
20 Animals That Will Kill You
A
Ant Kingdom
Atkins Diet
B
Battle of the Brains
Body Talk
I don't even know where to start!
I'm not asking anyone to do this for me; I just need a push in the right direction.
Any help will be appreciated.
Hi, I have a searchbar which looks for a value in my tables, it works great but i want to know how i can make the results of the search clickable; go to a page relevent to that search, let me explain in more depth. User searches for a postcode, script finds and displays the postcode on the next page, user clicks the result postcode to goto the next page. What im stuck with is how to take that result and automatically display it on the clicked "final" page? Search script: Code: [Select] <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("xxxxx","xxxx","xxxx"); //(host, username, password) //specify database ** EDIT REQUIRED HERE ** mysql_select_db("removalspacelogin") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "(SELECT postcode FROM freelistings WHERE postcode like '%$trimmed%') UNION (SELECT postcode FROM basicpackage WHERE postcode like '%$trimmed%') UNION (SELECT postcode FROM premiumuser WHERE postcode like '%$trimmed%') ORDER BY postcode"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); $result = mysql_query($query) or die("<b>Query:</b> $query<br><b>Error</b>: " . mysql_error()); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results for $q"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $title = $row['postcode']; echo " $title" ; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> <form method="post" action="localarea.php"> <a href="localarea.php"><?php echo """ .$var. ""</p>";?></a> </form> [\code] The form at the bottom im guessing is where i should take the $var from but how exactly? or if not where should it be pulled from to display on the next page? I want this "next" page because ideally there would be lots of results in postcode, so the user can choose which one is more relevant to them and go to that specific page with all the companies within that postcode. Hope this helps for a better understanding of what im trying to achieve, its just implementing it in? Ok, here's my code: How do i make it so that it outputs a maximum of only 5 results from the query where the img file exists. When I add LIMIT to the sql query it doesnt work so I guess its something else, but I have no clue. Can anyone help? $query = mysql_query("SELECT * FROM table WHERE date >= '$now' ORDER BY max(date) desc"); while ($row = mysql_fetch_assoc($query)) { $cid = $row['cat_id']; $title = $row['name']; $seoname = $row['seourl']; $img = 'images/'.$seoname.'.jpg'; if (!file_exists($img)) { $img = ''; } else { $img = 'images/'.$seoname.'.jpg'; } if (!empty($img)) { echo '<a href="images/'.$seoname.'/"><img src="'.$img .'" style="width:528px;" alt="" /></a>' . "\n"; } } Thanks. Hello community, I am working on a database of specialties in the hospital I work. The doctor's referral requests are sent to a mySQL database and I have, with the help of online guidance, produced a working php script that displays the information I need it to. However, I need it a little bit more specific. I intend to make multiple copies of this file for each specialty, so that when they open the file they only have the requests for that particular specialty. My question is, with reference to my code below, can I make echo information so that online, for instance, if 'specialty1 = gastroenterology' (as in, that particular specialty that that referral request is for), then only the rows on the database that have that particular text are displayed only? Hope that makes sense. Code below for your reference and assistance is highly appreciated. <!DOCTYPE html> <html> <head> <title>Specialty Referral Form</title> <style> table { border-collapse: collapse; width: 100%; color: #000000; font-family: arial; font-size: 10px; text-align: center; } th { background-color: #588c7e; color: white; } tr:nth-child(even) {background-color: #f2f2f2} </style> </head> <body> <table> <tr> <th>Patient Details</th> <th>Hospital Number</th> <th>Date of Birth</th> <th>Referred by:</th> <th>New/Repeat Visit to Patient</th> <th>Specialty</th> <th>Admission Date</th> <th>Too Ill for Clinic?</th> <th>Diagnosis Aware?</th> <th>Question</th> <th>History</th> <th>Medications</th> <th>Examination</th> <th>Results</th> <th>WorkingDiagnosis</th> <th>Investigation(s) Requested</th> </tr> <?php $conn = mysqli_connect("localhost", "view", "", "referral"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT patientdetails, hospitalnumber, DoB, referral, admission, specialty1, admissiondate, illness, awareness, question, history, medications, examination, results, workingdiagnosis, investigations FROM referralform"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while ($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["patientdetails"]. "</td><td>" . $row["hospitalnumber"] . "</td><td>" . $row["DoB"] . "</td><td>" . $row["referral"] . "</td><td>" . $row["admission"] . "</td><td>" . $row["specialty1"] . "</td><td>" . $row["admissiondate"] . "</td><td>" . $row["illness"] . "</td><td>" . $row["awareness"] . "</td><td>" . $row["question"] . "</td><td>" . $row["history"] . "</td><td>" . $row["medications"] . "</td><td>" . $row["examination"] . "</td><td>" . $row["results"] . "</td><td>" . $row["workingdiagnosis"] . "</td><td>" . $row["investigations"]. "</td></tr>"; } echo "</table>"; } else { echo "0 results"; } $conn->close(); ?> </table> </body> </html> I guess what I am looking for is something like echo specialty1 IF it writes a particular specialty and only that specialty. Thank you. Edited April 2, 2020 by samanji have built pages that paginate with 10 rows per page (some pages show more but for the moment i want to focus on this particular page)
//Define Some Options for Pagination $num_rec_per_page=10; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $num_rec_per_page; $results = mysql_query("SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name) LIMIT $start_from, $num_rec_per_page") or die(mysql_error()); $results_array = array(); while ($row = mysql_fetch_array($results)) { $results_array[$row['characterID']] = $row; }The above sets the variables for the pagination and below the results are echo with 10 rows per page then i show the pagination links: <?php $sql = "SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name)"; $rs_result = mysql_query($sql); //run the query $total_records = mysql_num_rows($rs_result); //count number of records $total_pages = ceil($total_records / $num_rec_per_page); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"><div style="width:100%; text-align:center;"> <ul class="pagination"> <li class="selected"> <?php echo "<a href='capitalmember.php?page=1'>".'«'."</a> ";?> </li> <? for ($i=1; $i<=$total_pages; $i++) { echo "<li><a href='capitalmember.php?page=".$i."'>".$i."</a></li> "; }; ?> <li class="selected"> <? echo "<a href='capitalmember.php?page=$total_pages'>".'»'."</a> "; // Goto last page ?></li> </ul></div> <?php $pageNr = $page; // Get Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 echo $pageNr; /* Result: From page 30 to 40 */ ?></td> </tr> </table>this works great and shows me 10 results per page, what i need to work out and work on next is: echo the number of results above the records (for example: "showing records 1 to 10" and then on page 2 "showing records 11 to 21" and page 3 "showing records 22 to 32" how can i work out the maths for this echo? i was thinking along the lines of; <?php $pageNr = $page; // Gets Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 // Now Show Results echo $from; // Echo from echo $to // Echo to ?>but i'm still working on this.. then i need to look at shortening the amount of page links on the page if for example i have 500 records it shows me links 1 to 50 and eats up the page.... Appreciate any help and light onto my problems. Many thanks Edited by jacko_162, 11 January 2015 - 05:43 PM. here is my code... please help <form method="get" action="shit3.php"> <input maxlength="50" size="50" type="text" name="q"> <input type="submit" value="SEARCH"> </form> <?php if (@$_GET['q']) { $var = $_GET['q'] ; $trimmed = trim($var); $limit=1; if ($trimmed == "") { echo "Please enter a search..."; exit; } if (!isset($var)) { echo "Container not found!"; exit; } mysql_connect("localhost", "xxx", "yyy") or die(mysql_error()); mysql_query("SET NAMES 'cp1251'"); mysql_select_db("agaexpor_container") or die("Unable to select database"); //select which database we're using $query = "select * from containertracking where vin like \"%$trimmed%\" order by vin"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if (empty($s)) { $s=0; } $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); $count = 1 + $s ; while ($row= mysql_fetch_array($result)) { $vin = $row["vin"]; $container = $row["container"]; echo "$count.) VIN: $vin <br />"; echo "container is: $container <br />"; $count++ ; } } ?> Hi folks, Complete No0b here when it comes to PHP and MySQL. I am in the middle of creating a PHP website. What I want to do is have the contents of a page in a MySQL table and have PHP gather the page content and display it on the page. Here is what I have in my home.tpl file: Code: [Select] <?php $query = "SELECT home, FROM $database_name"; $result = mysql_query($query); ?> And, in my index.php I simply call that home.tpl to display the data by using: Code: [Select] <?php include 'templates/default/home.tpl'; ?> Now, all I get is a blank page on index.php. Is there something else I should be doing? Remember, I am a complete No0b! Thanks folks. Hi, Im trying to retrieve HTML from a mysql database but nothing i've tried seems to work. The HTML im trying to retrieve is an iframe with a link and styles (code from amazon associates). Im trying to display links to specific products on amazon from the product page on my site. All data about the product is retrieved from the database so i have code to select the amazon link row in my database table but i cant get it to display. It says the html isnt a string so i cant echo it, fair enough. I have tried using the following code: Code: [Select] $get_buylink_sql = "SELECT mobo_buylink FROM mobo WHERE mobo_id = $mobo_id"; $get_buylink_res = mysqli_query($mysqli, $get_buylink_sql) or die(mysqli_error($mysqli)); while ($buylink = mysqli_fetch_array($get_buylink_res)) { echo"<iframe src=\"".$buylink."\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"></iframe>"; } mysqli_free_result($get_buylink_res); mysqli_close($mysqli);I have also tried putting the whole iframe code in the database which didnt work either. The mobo_id variable works fine for retrieving the rest of the data and i need to get the amazon link from the same record. I hope i've put this in a way you can understand, but if not i'll try and explain better and give you a link to my site if needed. Thanks, Alex I want to use session to do a query and will I be able to do this? I have a session that was gathered from login and now i was to use this session to do a query If Yes, How? I insert multiple id from my checkbox to mysql database using php post form. in e.x i insert id (checkbox value table test) to mysql. no i need to any function for retrieve data from mysql and print to my page with my e.x output.(print horizontal list name of table test where data = userid) my checkbox value ( name table is test ) : Code: [Select] 01 ---id----- name ---- 02 ---1 ----- test1 ---- 03 ---2 ----- test2 ---- 04 ---3 ----- test3 ---- 05 ---4 ----- test4 ---- 06 ---5 ----- test5 ---- 07 ---6 ----- test6 ---- 08 ---7 ----- test7 ---- 09 ---8 ----- test8 ---- 10 ---9 ----- test9 ---- mysql data Insert ( name of table usertest ): Code: [Select] 1 ---id----- data ---- userid ----- 2 ---1 ----- 1:4:6:9 ---- 2 ----- 3 ---2 ----- 1:2:3:4 ---- 5 ----- 4 ---3 ----- 1:2 ---- 7 ----- example outout : ( print horizontal list name of table test where data = userid ) print? Code: [Select] 1 user id 2 choise : test1 - test4 - test6 - test9 Thanks Hello everybody!
I am trying to figure out how to obtain all the data related to a key, but I've got no results so far and I am becoming really frustated, let's see if any of you could help me out with this.
Imagine I have a table with several columns, but we bother about two of them, let's say we have serial numbers of some product, on the left Incoming serial number (we can repair or swap the unit), on the right the outcoming serial number (same if we have repared the unit, different if we swap it for another unit).
Then we have, for example:
A -> A (Unit A enters and we repaired it)
A -> B (Same unit came another day for some reason and we couldn't repair it, so we swap it by giving B to the customer)
B -> C (Unluckily B was defective so we have to change it again)
C -> C (C had another problem and we repaired it)
We have that in the database from different days and the such, so now, we want to know the historical and we know "C". If we perform a SELECT * FROM... WHERE incoming/outcoming serial number = "C" we'll get:
B -> C
C -> C
So we should seek now for B and keep going... but I cannot proceed correctly, 'cause if I SELECT using B I'll get again B -> C (and A -> B, what I want), but when do I know I have to finish? How could I implement this as a function or whatever? showing every not repeated line from the beginning.
Could your minds help mine? Thank you very much in advance!.
I am trying to iterate through a 3 dimensional array and echo out all the details. I am having a trouble with the following: Array ( [DT_Intrinsic_mob7] => Array ( [0] => Array ( [cli] => 11111111111 [min] => 533 ) [1] => Array ( [cli] => 2222222222 [min] => 536 ) [2] => Array ( [cli] => 33333333333 [min] => 541 ) ------- SNIP ----- [46] => Array ( [cli] => 5555555555 [min] => 5471 ) ) [DT_belltel_mob7] => Array ( [0] => Array ( [cli] => 999999999 [min] => 508 ) [1] => Array ( [cli] => 8888888888 [min] => 519 ) [2] => Array ( [cli] => 7777777777 [min] => 602 ) [3] => Array ( [cli] => 7975757375 [min] => 701 ) ) ) My code looks like this: foreach ($cli_data as $key => $value){ foreach ($cli_data[$key] as $key2 => $value2){ foreach($cli_data[$key][$key2] as $key3 => $value3){ echo "key3 is $key3 \n"; echo "value is $value3['cli']"; } } echo "\n\n"; } I keep getting the following error PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/index.php on line Thanks To generate the stockroom drop down list function einv_generateStockrmSelectDropdown($Stockrm,$field,$dropdown) { //connect to database base_connectDatabase(); echo "<select id=\"stockrm\" name=\"".$field."[]\" multiple=\"multiple\" style=\"align:left\" class=\"form-control\">"; if (isset($Stockrm) && ($Stockrm != "")) { $stockrmname = einv_getStockrmDetail($Stockrm); echo "<option value=\"". $Stockrm ."\">". $stockrmname['einv_stockrm_name'] ."</option>"; } else { $Stockrm = 0; } $getStockrmSQL = base_executeSQL("SELECT * FROM einv_stockroom WHERE einv_stockrm_id<>" . $Stockrm . " ORDER BY einv_stockrm_name"); while ($Stockrmdata_row = base_fetch_array($getStockrmSQL)) { if (base_num_rows($getStockrmSQL)!= 0) { echo "<option value=\"".$Stockrmdata_row['einv_stockrm_id']."\">".$Stockrmdata_row['einv_stockrm_name']."</option>"; } } echo "</select>"; echo "<script src=\"../terms_base/js/jquery.multiple.select.js\"></script>"; //Input some codes to split the dropdown and make it into the setSelects. By default, the first time = AutoSelectAll if(isset($dropdown) && ($dropdown != "")) { //dropdown = 1;2;3 $SDDArrays = explode(";", $dropdown); $countTrap0 = count($SDDArrays); $drop = "$('#stockrm').multipleSelect(\"setSelects\", ["; $counting = 1; foreach ($SDDArrays as &$value) { if ($countTrap0 != $counting) { $drop .= "'". $value . "',"; } else { $drop .= "'". $value . "'"; } $counting++; } $drop .= "]);\n"; } elseif (isset($dropdown)) { //dropdown= $drop = "$('#stockrm').multipleSelect(\"uncheckAll\")"; } else { // $drop = "$('#stockrm').multipleSelect(\"checkAll\")"; } echo "<script>\n"; echo "$(function() {\n"; echo "".$drop.""; echo "});\n"; echo "$(\"#stockrm\").multipleSelect({ onClose: function() { document.getElementById('search').click(); }});\n"; echo "$(\"#stockrm\").multipleSelect();\n"; echo "</script>"; //close the database base_closeDatabase(); }add stockroom function //This function is use to add new stock room //code = stock room code //name = stock room name //desc = stock room description //remark = stock room remark //cat = stock room category function einv_addStockrm($code,$name,$desc,$remark,$cat) { //connect to database base_connectDatabase(); $User = base_getUserDetail($_SESSION['uID']); base_executeSQL("INSERT INTO einv_stockroom (einv_stockrm_code, einv_stockrm_name, einv_stockrm_desc, einv_stockrm_remark, einv_stockrm_cat) VALUES ('" . $code . "', '" . $name . "', '" . $desc . "', '" . $remark . "', '" . $cat . "')"); base_addTransactionLog('Manage Stock Room', 'Add', " Stock Room Code = " . $code . " || Stock Room Name = " . $name . " || Stock Room Description = " . $desc . " || Stock Room Remark = " . $remark . " || Stock Room Category = " . $cat . " "); //go to stock room page echo '<script type="text/javascript">' . "\n"; echo 'window.location="../einventory/stockrm_list.php";'; echo '</script>'; //close the database base_closeDatabase(); } Edit stockroom function einv_editStockrm($srid,$code,$name,$desc,$remark,$cat) { //connect to database base_connectDatabase(); $User = base_getUserDetail($_SESSION['uID']); $Stockroom = einv_getStockrmDetail($srid); base_executeSQL("UPDATE einv_stockroom SET einv_stockrm_code='" . $code . "', einv_stockrm_name='" . $name . "', einv_stockrm_desc='" . $desc . "', einv_stockrm_remark='" . $remark . "', einv_stockrm_cat = '" . $cat . "' WHERE einv_stockrm_id=" . $srid . ""); base_addTransactionLog('Manage Stock Room', 'Edit', " Stock Room Code = " . $code . " || Stock Room Name = " . $name . " || Stock Room Description = " . $desc . " || Stock Room Remark = " . $remark . " || Stock Room Category = " . $cat . " "); //go to stock room page echo '<script type="text/javascript">' . "\n"; echo 'window.location="../einventory/view_stockrm.php?id='. $srid .'";'; echo '</script>'; //close the database base_closeDatabase(); } I have a dropdown list named **Stockroom** where it displays an array of values. Example: **Stockroom** 1. [A] 2. [b] 3. [C] When user clicks on [A], it will display relevant data fields that [A] possess (appears below stockroom ddl). And as user clicks on [b], there is an onchange function that will then show [b] data fields (fields in A is deleted and replaced with B). I am able to add the initial values however, as i want to edit and change the stockroom from [A] to [b] which will result in a whole new data to be stored, i am unable to do so. Any ideas? I believe i have to amend my edit stockroom function where i require a set of coding such as If the array is selected, i have to delete existing data and add new data in accordance to the selected ID. Edited by mac_gyver, 14 January 2015 - 07:05 AM. code tags around posted code please I m trying to fetch a image from mysql (blob) with header..here is my coding..."<?php include("db.php"); $query=mysql_query("select * from table where id='3' "); $row=mysql_fetch_array($query); $r=$row['image']; header("content-type:image"); echo $r; ?>" i want to fetch another fields from the database....but when i try to echo another fields...the page shows error or it does not echo other fields of database....please help me...how can i resolve it...i want to fetch other fields from database,like'username'password'firstname'lastname and image...thanks in advance... |