RE: [PHP-DB] get all records but limit to 6
I think the problem is he wants to limit after he's sorted them. The only way I know of to do that is to do the whole query without a limit clause, then run through the results but only do whatever you have to do with the first 6. -- Marcjon -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] get all records but limit to 6
select * from table order by datetime_field desc limit 0,6 Peter > -Original Message- > From: Gawie Marais [mailto:[EMAIL PROTECTED] > Sent: 14 June 2004 07:20 > To: [EMAIL PROTECTED] > Subject: [PHP-DB] get all records but limit to 6 > > > hi, > > i need to get only the first 6 records sorted by datetime from > the thousands > of records in existance. how do i do that ? > > thus, only the latest 6 records added to the database should be displayed > and this can be done with the datetime field in the database. can anyone > help with the php code please ? > > > > regards, > > gawie. > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > Email has been scanned for viruses and SPAM by Trader Mailmanager > www.trader.uk.com > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] get all records but limit to 6
hi, i need to get only the first 6 records sorted by datetime from the thousands of records in existance. how do i do that ? thus, only the latest 6 records added to the database should be displayed and this can be done with the datetime field in the database. can anyone help with the php code please ? regards, gawie. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL persistent connections
Hello, I am no expert but I believe more information is required, like what would be the average return of a mysql operation ? How many different DB's are you accessing ? How many different usernames and passwords for mysql are you using ?? I believe persistent connections are only useful when the amount of DB connections being made is inversely proportional to the amount of data being returned. That is if you have 50 connections being created to check the same one field in one table. Then persistent connections would be worth it. But is you are returning 4-5MB of data per-query then persistent connections would not be worth it. Plus with persistent connections I have heard most people have issues with hitting the too many open connections limit. Because the connections are not being closed or reused. Michael. On Fri, 11 Jun 2004 11:38:37 -0400 Radek Zajkowski <[EMAIL PROTECTED]> wrote: > > > Hey there PHP fiends, > > I have a bit of cookie here. We're designing a PHP based app that uses > MySQL as the data storage. Scalability is an issue, we want to be able > to handle up to 1 people utilizing the system (not at once of > course). > > Question is, should I be connecting and disconnecting from the DB on > each operation or increase the maximum number of allowed connections > with MySQL and connect just once. > > TIA > > R> > > - > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql not receiving the data
Some of the reason to have "register_global" on is to easly use variables sent by post, get, cookie method of a form. Ex. in your code at the page "anypage.php" you will have available the variables: $get_var==1 and $text_post=="Hello World" if "register_global=TRUE " in php.ini file - in this case u still have available $_POST;GET ecc... $_GET['get_var']==1 and $_POST['text_post']=="Hello World" if "register_global=FALSE " in php.ini file - in this case you don't have the $get_var e $text_post available, so code is safer I would suggest to leave register global=FALSE as to have safer code unless u have to rewrite the whole code. Think about having hacked variables value send by GET, COOKIE method. Bye "Hans Lellelid" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > Hi Andrew, > > Andrew Rothwell wrote: > > Thank you everybody that responded so quickly - > > I used the suggestion of Franciccio - and the data is now gow into the db > > Thank you very much - I really appreciate the help. > > > > Another question - with this fix in place - do I still need the > > register_globals = On ? > > Or can I now turn it off? > > > > It seems like you should have kept your old php.ini file, as this other > error you encountered was probably due to your old php.ini file having > this setting: > > magic_quotes_gpc = 1 > > That INI var instructs PHP to automatically addslashes() to any > GET/POST/COOKIE data. I would suggest turning this back on, unless > you've thoroughly redesigned your code to not need it. > > This is unrelated to register_globals, which you will need to leave on > unless you redesign your application. > > Hans -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] creating a nested multidimensional array from a query
Hi :) I am on my second week of php so be gentle I am creating an XML file out of a mysql query with nested arrays. Currently I can get 1 element and 1 child with a properly formatted XML file with the below script . My question is: How do I add 3 to 4 more child elements to the below 'playlist' array ? Currently ,I have one parent 'Artist' and one child 'english' ... I need to add more child elements to the 'Artist' array like urlPath, spanish, biography, etc Do I have to add another dimension to the 'playlist' array? Do I need another foreach loop ? Is there an easier more efficient way to do this? Be nice to spell out the schema in some way in the script...in case you need to add more levels...like a 'subCategory' I am a bit new to this so any help would be greatly appretiated head is spinning a bit $sql = 'SELECT artist.artist_name, media.english, media.path '; $sql .= 'FROM media, artist '; $sql .= 'WHERE artist.artist_id = media.artist_id LIMIT 0, 30 '; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { $playlist[$row['artist_name']] [] = $row['english']; //would like to add more children here... } $xml = "\n"; foreach ($playlist as $artist => $media) { $num_media = count($media); $xml .= "\n"; $xml .= "\t\n"; $xml .= "\t\t".$artist."\n"; $xml .= "\t\n"; $xml .= "\t\n"; foreach ($media as $mediaVal) { $xml .= "\t\t\n"; $xml .= "\t\t\t".$mediaVal."\n"; ///add more children ///add more children $xml .= "\t\t\n"; } $xml .= "\t\n"; $xml .= "\n"; } $xml .= "\n"; print $xml -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql not receiving the data
Hi Andrew, Andrew Rothwell wrote: Thank you everybody that responded so quickly - I used the suggestion of Franciccio - and the data is now gow into the db Thank you very much - I really appreciate the help. Another question - with this fix in place - do I still need the register_globals = On ? Or can I now turn it off? It seems like you should have kept your old php.ini file, as this other error you encountered was probably due to your old php.ini file having this setting: magic_quotes_gpc = 1 That INI var instructs PHP to automatically addslashes() to any GET/POST/COOKIE data. I would suggest turning this back on, unless you've thoroughly redesigned your code to not need it. This is unrelated to register_globals, which you will need to leave on unless you redesign your application. Hans -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Mysql not receiving the data
Thank you everybody that responded so quickly - I used the suggestion of Franciccio - and the data is now gow into the db Thank you very much - I really appreciate the help. Another question - with this fix in place - do I still need the register_globals = On ? Or can I now turn it off? Thank you all again Andrew -Original Message- From: franciccio [mailto:[EMAIL PROTECTED] Sent: Sunday, June 13, 2004 12:26 PM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Mysql not receiving the data I agree, the slashes are killing the query. I would suggets doing this: $add = "INSERT INTO movies SET > movie_name=\"$movie_name\", > genre=\"$genre\", > director=\"$director\", > star1=\"$star1\", > star2=\"$star2\", > star3=\"$star3\", > brief_synopsis=\"$brief_synopsis\", > imdb_link=\"$imdb_link\""; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Problem in passing the necessary variable.
Ciao..hi, i would suggest to embed the html code in php like this: "; ?> If it works let me know , bye Francesco Basile __ "Alessandro Folghera" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > Hi, > > I have developed a news system .. I can select to insert an image into the > articles. > > The function to extract the image calling them by the "imgid" of images > table is the following: > > function getImm() { > ?> > > connect(); > $sql = "select * from images"; > $result = mysql_query($sql); > while($row = mysql_fetch_array($result)) { > printf("%s", $row["id_img"], $row["imgid"]); > } > ?> > > > I'd like to be able to see the image before to publish the piece of news. > > I think about a window pop up with java in order to create a preview of the > image. The code follows: > > onClick="window.open(this.href, this.target, 'width=200,height=250'); > return false;"> > > The problem is that I can't pass the "imgid" to the href inspite of the > > > May someone tell me how to pass the id number in order to show me the image > or how may I solve the trouble? > > I hope someone will help me ... > > Sincerely, > Alexander -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql not receiving the data
I agree, the slashes are killing the query. I would suggets doing this: $add = "INSERT INTO movies SET > movie_name=\"$movie_name\", > genre=\"$genre\", > director=\"$director\", > star1=\"$star1\", > star2=\"$star2\", > star3=\"$star3\", > brief_synopsis=\"$brief_synopsis\", > imdb_link=\"$imdb_link\""; "Rich Hutchins" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > The apostrophe (') in your data is, most likely, killing the SQL statement > when it is sent to the server. Use addslashes() around all of your form data > to prevent this and also to help guard against SQL injection attacks. > > Ex: > > $add = "INSERT INTO movies SET > movie_name='".addslashes($movie_name)."', > genre='".addslashes($genre)."', > director='".addslashes($director)."', > star1='".addslashes($star1)."', > star2='".addslashes($star2)."', > star3='".addslashes($star3)."', > brief_synopsis='".addslashes($brief_synopsis)."', > imdb_link='$imdb_link'"; > > Hope this helped. > Rich > -Original Message- > From: Andrew Rothwell [mailto:[EMAIL PROTECTED] > Sent: Sunday, June 13, 2004 1:48 PM > To: [EMAIL PROTECTED] > Subject: RE: [PHP-DB] Mysql not receiving the data > > > Hi Larry, Thank you very much for the very quick response, I set my php.ini > file (located /etc/php.ini ) for the register_globals = On (it was off by > default) > > Now however I get an error > Error adding entry: You have an error in your SQL syntax near 's spanish > driver is found shot dead, Inspector Jacques Clouseau is the first off' at > line 8 > > My Database is a movie database of my dvd's that I own (for insurance > reasons) > > My addmovie.php is this >mysql_connect("localhost","username","password"); > mysql_select_db("movies"); > $add = "INSERT INTO movies SET > movie_name='$movie_name', > genre='$genre', > director='$director', > star1='$star1', > star2='$star2', > star3='$star3', > brief_synopsis='$brief_synopsis', > imdb_link='$imdb_link'"; > if (@mysql_query($add)) > { > echo("Your entry has been added. > $movie_name"); > } > else > { > echo("Error adding entry: " . > mysql_error() . ""); >} > ?> > > > And the addmovie.htm page (atleast the form action is this) > > > >bordercolordark="#FF0033" bordercolorlight="#66"> > > Movie Name > > > > > > > Andrew > > -Original Message- > From: Larry E. Ullman [mailto:[EMAIL PROTECTED] > Sent: Sunday, June 13, 2004 11:22 AM > To: Andrew Rothwell > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP-DB] Mysql not receiving the data > > > Online I could see everything, and the pages gave the appearance of > > working, however when I went into the DB using PHPMYADMIN to check the > > status of the new data entered, all I found was blank rows ( for the > > new data since the rebuild, all the old data was there) There were the > > correct number of new rows for the amount of records that I had > > entered, which tells me (unless I am nistaken) that the PHP is talking > > to the DB, and is atleast sending a insert command, but the rest of > > the data is not getting in. - > > Without seeing any code whatsoever and since this worked before but no > longer works on a new install, I can only assume that your code was written > with the assumption that register_globals was turned on and it's not on in > your current configuration. > > If that is the case, see the PHP manual or search the Web for the solution > ($_POST, $_GET, etc.). > > Larry > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Mysql not receiving the data
The apostrophe (') in your data is, most likely, killing the SQL statement when it is sent to the server. Use addslashes() around all of your form data to prevent this and also to help guard against SQL injection attacks. Ex: $add = "INSERT INTO movies SET movie_name='".addslashes($movie_name)."', genre='".addslashes($genre)."', director='".addslashes($director)."', star1='".addslashes($star1)."', star2='".addslashes($star2)."', star3='".addslashes($star3)."', brief_synopsis='".addslashes($brief_synopsis)."', imdb_link='$imdb_link'"; Hope this helped. Rich -Original Message- From: Andrew Rothwell [mailto:[EMAIL PROTECTED] Sent: Sunday, June 13, 2004 1:48 PM To: [EMAIL PROTECTED] Subject: RE: [PHP-DB] Mysql not receiving the data Hi Larry, Thank you very much for the very quick response, I set my php.ini file (located /etc/php.ini ) for the register_globals = On (it was off by default) Now however I get an error Error adding entry: You have an error in your SQL syntax near 's spanish driver is found shot dead, Inspector Jacques Clouseau is the first off' at line 8 My Database is a movie database of my dvd's that I own (for insurance reasons) My addmovie.php is this Your entry has been added. $movie_name"); } else { echo("Error adding entry: " . mysql_error() . ""); } ?> And the addmovie.htm page (atleast the form action is this) Movie Name Andrew -Original Message- From: Larry E. Ullman [mailto:[EMAIL PROTECTED] Sent: Sunday, June 13, 2004 11:22 AM To: Andrew Rothwell Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Mysql not receiving the data > Online I could see everything, and the pages gave the appearance of > working, however when I went into the DB using PHPMYADMIN to check the > status of the new data entered, all I found was blank rows ( for the > new data since the rebuild, all the old data was there) There were the > correct number of new rows for the amount of records that I had > entered, which tells me (unless I am nistaken) that the PHP is talking > to the DB, and is atleast sending a insert command, but the rest of > the data is not getting in. - Without seeing any code whatsoever and since this worked before but no longer works on a new install, I can only assume that your code was written with the assumption that register_globals was turned on and it's not on in your current configuration. If that is the case, see the PHP manual or search the Web for the solution ($_POST, $_GET, etc.). Larry -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql not receiving the data
Andrew Rothwell wrote: Hi Larry, Thank you very much for the very quick response, I set my php.ini file (located /etc/php.ini ) for the register_globals = On (it was off by default) Now however I get an error Error adding entry: You have an error in your SQL syntax near 's spanish driver is found shot dead, Inspector Jacques Clouseau is the first off' at line 8 I would think it fairly obvious that the extra "'" in the text you are loading is causing a problem, use an "`" instead, or "escape" the single "'" Not sure if MySQL uses "''" or "\'" :) -- Lester Caine - L.S.Caine Electronic Services -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Mysql not receiving the data
Hi Larry, Thank you very much for the very quick response, I set my php.ini file (located /etc/php.ini ) for the register_globals = On (it was off by default) Now however I get an error Error adding entry: You have an error in your SQL syntax near 's spanish driver is found shot dead, Inspector Jacques Clouseau is the first off' at line 8 My Database is a movie database of my dvd's that I own (for insurance reasons) My addmovie.php is this Your entry has been added. $movie_name"); } else { echo("Error adding entry: " . mysql_error() . ""); } ?> And the addmovie.htm page (atleast the form action is this) Movie Name Andrew -Original Message- From: Larry E. Ullman [mailto:[EMAIL PROTECTED] Sent: Sunday, June 13, 2004 11:22 AM To: Andrew Rothwell Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Mysql not receiving the data > Online I could see everything, and the pages gave the appearance of > working, however when I went into the DB using PHPMYADMIN to check the > status of the new data entered, all I found was blank rows ( for the > new data since the rebuild, all the old data was there) There were the > correct number of new rows for the amount of records that I had > entered, which tells me (unless I am nistaken) that the PHP is talking > to the DB, and is atleast sending a insert command, but the rest of > the data is not getting in. - Without seeing any code whatsoever and since this worked before but no longer works on a new install, I can only assume that your code was written with the assumption that register_globals was turned on and it's not on in your current configuration. If that is the case, see the PHP manual or search the Web for the solution ($_POST, $_GET, etc.). Larry -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql not receiving the data
Online I could see everything, and the pages gave the appearance of working, however when I went into the DB using PHPMYADMIN to check the status of the new data entered, all I found was blank rows ( for the new data since the rebuild, all the old data was there) There were the correct number of new rows for the amount of records that I had entered, which tells me (unless I am nistaken) that the PHP is talking to the DB, and is atleast sending a insert command, but the rest of the data is not getting in. - Without seeing any code whatsoever and since this worked before but no longer works on a new install, I can only assume that your code was written with the assumption that register_globals was turned on and it's not on in your current configuration. If that is the case, see the PHP manual or search the Web for the solution ($_POST, $_GET, etc.). Larry -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Mysql not receiving the data
Good day list, I was running a Mysql/PHP DB/Webpage that was hosted on Redhat 8.0 It was a simple DB - only 1 table, and the php page connected and fed data to it. Last weekend I rebuilt the server to Fedora Core 2 - using the default PHP/Mysql/apache installs. I setup the databases, and imported the old data (taken from a MySQL dump) into the new DB, and setup Apache, so that I could view the pages that displayed the data, and also the page that I used to add the data. Online I could see everything, and the pages gave the appearance of working, however when I went into the DB using PHPMYADMIN to check the status of the new data entered, all I found was blank rows ( for the new data since the rebuild, all the old data was there) There were the correct number of new rows for the amount of records that I had entered, which tells me (unless I am nistaken) that the PHP is talking to the DB, and is atleast sending a insert command, but the rest of the data is not getting in. - I hope that I have made sense, Please note that the php/html pages used to input the data used to work on the old server and had been running for several years flawlessly. As I said I have a default conf for apache, obviously changing the bits that needed to be changed (servername, etc) and did not change anything on the PHP & MySQL confs. Any ideas? Thank you Andrew Rothwell -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: how to reuse DB results
Hi here is my logic, i haven't tested but it should work (i hope)!!! i'm not sure if it works only on php5...!?! Let me know if it is a complete crap i've just started learning php. Bye $recordset=mysql_query($query); // whatever query is $obj_array=new ArrayObject($recordset); // get the iterator now $interator=$obj_array->getIterator(); // you can now easly navigate in the recordset by the iterator /* define an array with n fields to be shown on top of page. Attention ...values name must be the same of table field names you want to show on top of the page*/ $my_key = array(0=>'key1',1=> 'key2',,n-1=>'keyn'); // echo the top of the page $i=0; while($iterator->valid()) { if ($iterator->key()==$my_key[$i] ) { echo "".$iterator->key()." : ".$iterator->current().""; /* if u need a top_array to store result shown on top of the page, uncomment this line only $top_array[$i]=$iterator->current(); // loose the matching key<->field!! */ $i++; $iterator->next(); } else $iterator->next(); } /* to display the whole recordset resulting from the query don't forget you still have $recordset free to use with mysql_fetch_array() or other way to display */ echo 'this is the bottom page and displays the whole result'; while ($res=mysql_fetch_array($recordset)) for each ($res as $k=>$val) echo "$k : $val"; // make your choice for html code "Aaron Wolski" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > Hi All, > > Got this logic problem I don't know how to solve. > > Is there any way I can make a call to the DB for some records. > > Display some info from a column or two say at the top of the page and > then display the full result set in a while() loop? > > Right now, I am making two calls to the Db to get the data I need to > display at the top of the page and then a second query to retrieve the > full result set. > > I'm confused! > > Thanks for any help! > > Aaron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: HTTP header information
You may try with this: // then here is all the html for that page Bye Basile Francesco "Philip Thompson" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > > On Jun 10, 2004, at 9:44 AM, Torsten Roehr wrote: > > > "Philip Thompson" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > >> Hi all. > >> > >> I am running a website to where a user needs to login to authenticate > >> themselves to perform certain tasks. So a user logs in, and I start a > >> session (in PHP, of course). Well, the catch is, I am doing this all > >> from one page, 'viewer.php', and I just tack on the specific view/page > >> that I want them to see, depending on the link selected on that page. > >> Meaning, they click on the 'submit problem' link and it goes to > >> 'viewer.php?type=submitproblem'. > >> > >> The problem comes whenever I load the view 'submitproblem' and I start > >> a session with session_start(), which carries over the variable to > >> tell > >> whether or not the user is logged in. If they have not logged in > >> whenever they click on 'submitproblem' then it will redirect them to > >> 'viewer.php?type=login'. So I log in, and then go to 'submitproblem'. > >> > >> This is where I get the error: "Warning: session_start(): Cannot send > >> session cookie - headers already sent". Essentially, I understand why > >> this is occurring, but is there an easy way to get around it without > >> creating a new page, such as 'submitproblem.php' instead of > >> 'viewer.php?type=submitproblem'??? > > > > Make sure that NO output is done before session_start() is called. Can > > you > > post some of your code? > > > > Regards, > > > > Torsten Roehr > > > > See, that's the case. Because I'm essentially just changing the content > within the page, it never leaves the page 'viewer.php' - it just > changes the content by tacking on '?type=login, submitproblem, etc'. > > But my code in the beginning of the file 'submitproblem.view' is: > > session_start(); > > if (!session_is_registered('_isLoggedIn')) { > header ("Location:viewer.php?type=login"); > } else { > // do the stuff to submit a problem if they have > // logged in and have pressed the "submit" button > // in the html > } > > ?> > > // then here is all the html for that page > > So, does that help any? > > ~Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Retrieve data from a table, edit/add it and enter it in a new table
I see one bug in your code , that is you never "rewind" the pointer of mysql_fetch_array($result), so at the end of the first cycle ...while ($r=mysq...)... the pointer is at the end of the query resource. You should use mysql_data_seek($result,0) to rewind before doing another while cycle. Hope it can help Bye Francesco Basile (PHP_newbee) "Justin" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] Hi, I am trying to do the following: Retrieve some information from a table, edit it by appending some further information to it (a few more fields) and then enter the new data record into a new table, and delete the old data in the original table. Sounds confusing I know. The code is below (I apologise for its poor style etc as I am very new to php), but when I click on the 'Enter Information' button, nothing happens. The existing data is retrieved without any problems and I can select it using the radio button. But when I try and add data to the new fields ('option_close_price' and 'notes'), nothing happens. Any help appreciated. \n"; print "Open DateShareCodeShort or Long TradeExpiryExcerciseOption PriceNumber PurchasedNumber SoldIncome InIncome Out "; while ($row = mysql_fetch_array($result)) { print ""; print ""; print ""; print $row["open_date"]; print ""; print $row["share"]; print ""; print $row["code"]; print ""; print $row["short_long_trade"]; print ""; print $row["expiry"]; print ""; print $row["excercise"]; print ""; print $row["option_price"]; print ""; print $row["no_purchased"]; print ""; print $row["no_sold"]; print ""; print $row["income_in"]; print ""; print $row["income_out"]; print "\n"; } print "\n"; ?> "> Option Close Price" SIZE=7 > Notes:" SIZE=60> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: how to reuse DB results
Sorry for mystakes, (shame on me, i said i was new) using Object array, here is a working version (tested) with use of array. Bye $recordset=mysql_query('SELECT * FROM my_tabella'); // or whatever query is /* define an array with fields to be shown on top of page. Attention ...values name must be the same of table field names you want to show on top of the page*/ $my_key = array('key01','key02','key03'); /* u can use $_REQUEST variables instead of fixed values*/ $i=0; while($record=mysql_fetch_array($recordset, MYSQL_ASSOC)) { foreach ($record as $k=>$val) if ($k==$my_key[$i]) { // echo the top of the page echo "$k :$val"; /* if u need a top_array to store result shown on top of the page, comment this line only $top_array[$i]=$val; // loose the matching key<->field!! */ $i++; } } //reset the resource mysql_data_seek($recordset,0); // some middle-page code here echo 'this is the bottom page and displays the whole result'; while ($record=mysql_fetch_array($recordset, MYSQL_ASSOC)) foreach ($record as $k=>$val) echo "$k : $val"; // make your choice for html code mysql_free_result($recordset); // Bye "Aaron Wolski" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > Hi All, > > Got this logic problem I don't know how to solve. > > Is there any way I can make a call to the DB for some records. > > Display some info from a column or two say at the top of the page and > then display the full result set in a while() loop? > > Right now, I am making two calls to the Db to get the data I need to > display at the top of the page and then a second query to retrieve the > full result set. > > I'm confused! > > Thanks for any help! > > Aaron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: mysql results, arrays, and for loops
Hi, here is my solution (one of the possible) it is tested so it should work fine: \n"; $record= mysql_fetch_array($recordset, MYSQL_ASSOC); foreach ($record as $k =>$val) { echo "$k\n"; // print the field name in the first row of the table for ($i=0;$i<$num_righe;$i++) { echo ""; mysql_data_seek($recordset,$i); $record = mysql_fetch_array($recordset, MYSQL_ASSOC); foreach ($record as $val){ echo "$val\n"; // print the result of query, starting under 1st row } } mysql_free_result($recordset); mysql_close(); echo ""; ?> Let me know if it fits your problem. Best regards Francesco Basile "Philip Thompson" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > Hi all! > > I am using a select statement to obtain all the dates whenever someone > submitted a problem in a database. Well, I want to get the result > (which could be multiple dates) and then print that in a table format > with some other information on a webpage. So I want to use a FOR loops > and go through each of the dates and dynamically create a table. > > My question is: how do I store the results of the select query? Would I > want to store them in an array, and then just parse through each > element of the array, and what is the syntax for that? Or is there a > better way? > > Thanks, > ~Philip -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php