wizardsandwars Posted December 30, 2002 Share Posted December 30, 2002 OK, If I wanted to write a quick litte script that queried the database, and stored the results in an array (to loop through later) I assume that I would do something like this <?php require("includes/application_top.php"); $customers = array(); $customers = tep_db_query("SELECT customers_firstname, customers_email_address FROM customers"); echo "$customers"; ?> when I execute this, I only receive a "Resource id #10" Any insight would be appreciated. ------------------------------------------------------------------------------------------------------------------------- NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit. If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help. Link to comment Share on other sites More sharing options...
jules Posted December 30, 2002 Share Posted December 30, 2002 wizardsandwars <?php require("includes/application_top.php"); $customers_query_raw = "select customers_firstname, customers_email_address from " . TABLE_CUSTOMERS . " order by customers_firstname"; $customers_query = tep_db_query($customers_query_raw); while ($customers = tep_db_fetch_array($customers_query)) { echo $customers['customers_firstname']; echo '<br>'; echo $customers['customers_email_address']; } ?> :lol: Jules :lol: Link to comment Share on other sites More sharing options...
Ian Posted December 30, 2002 Share Posted December 30, 2002 You forgot to load the result set. <?php require("includes/application_top.php"); $customers_query = tep_db_query("SELECT customers_firstname, customers_email_address FROM customers"); $customers=tep_db_fetch_array($customers_query); echo $customers['customers_firstname']; //etc for other fields ?> Note as this query will return more than 1 row in the result set you would also have to traverse the result set using while loop e.g. while ($customers=tep_db_fetch_array($customers_query)) { // processing } Trust me, I'm an Accountant. Link to comment Share on other sites More sharing options...
wizardsandwars Posted December 30, 2002 Author Share Posted December 30, 2002 OK, so an Array in PHP acts much like a Hash in perl, where you have to transverse it in order to display it. I see. So it looks like the variable contained the result set, I just wasn't displaying it properly. One more question. How do you write to a file? I assume we'd use a file pointer, like this, $fp=("/data.dat", "w"); But in perl, I would use this file pointer in a print statement, like this print $fp "here is what I wnat to store in the file"; How would I do this in pHP? ------------------------------------------------------------------------------------------------------------------------- NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit. If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help. Link to comment Share on other sites More sharing options...
wizardsandwars Posted December 30, 2002 Author Share Posted December 30, 2002 Upon further review, it looks as if I misunderstood the tep functions. I need to use both the tep_db_fetch_array and the tep_db_query. OK. Now for file access. Can you give me an example of how to write the contents of a variable to a file, and how to read the contents of a file into a variable using PHP? Seriously appreciate it. ------------------------------------------------------------------------------------------------------------------------- NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit. If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help. Link to comment Share on other sites More sharing options...
Ian Posted December 30, 2002 Share Posted December 30, 2002 try $fp = fopen("dir/myfile.txt", "w"); fputs($fp, "Hello World"); fclose($fp); and of course you could also do $myVar="hello world"; $fp = fopen("dir/myfile.txt", "w"); fputs($fp, $myVar); fclose($fp); as for reading this depends on the structure of the file and what you want to achieve try http://www.php.net/manual/en/ref.filesystem.php for more info Trust me, I'm an Accountant. Link to comment Share on other sites More sharing options...
wizardsandwars Posted December 30, 2002 Author Share Posted December 30, 2002 Looks greek to me. I tried there, but I don't understand 2 words on the whole page. And I'm a programmer, lol. Anyway, what I want to store in the file is a single integer, such as a customer ID. So I wouln't need any delimiter. Just a n at the end of an integer. Could you show me an example of how to read this, or point me to a function that would d othis? ------------------------------------------------------------------------------------------------------------------------- NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit. If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help. Link to comment Share on other sites More sharing options...
Ian Posted December 31, 2002 Share Posted December 31, 2002 Ok, more specific http://www.php.net/manual/en/function.fopen.php http://www.php.net/manual/en/function.fgets.php in particular the fgets link does provide an eaxample pf reading line by line Trust me, I'm an Accountant. Link to comment Share on other sites More sharing options...
wizardsandwars Posted December 31, 2002 Author Share Posted December 31, 2002 Cool. That did it. I think I've got enought to get me finished with this little project of mine. Thanks. ------------------------------------------------------------------------------------------------------------------------- NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit. If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.