VTS Posted August 10, 2006 Share Posted August 10, 2006 What I was trying to do was use array_slice to pick a store id and store it into a variable so I can display it. When I used it like this, I got an array returned instead of a single value. If you are wondering why I don't just use a while statement, it is because this is part of a page that is going to be displayed for one store at a time and is controlled by a submit button. If you have problems understanding what I am trying to do just let me know and I will try to clarify. By the way, run_sql() is a function I set up to use anytime I want to run a sql query if you were wondering. Here is the code I am using:[code] $sql = "SELECT COUNT(*) num FROM store WHERE store_open_closed = 'o'"; $result = run_sql($sql) or die(mysql_error()); $storesql = "SELECT store_id FROM store WHERE store_open_closed = 'o' ORDER BY store_id"; $sql10 = run_sql($storesql) or die(mysql_error()); $sql11 = mysql_fetch_array($sql10); $stores = mysql_fetch_array($result); $x =0; if($x < $stores['num']){ $storenbr = array_slice($sql11,$x,1); echo "store #: ".$storenbr; }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/ Share on other sites More sharing options...
sasa Posted August 10, 2006 Share Posted August 10, 2006 array_slice retur arraytry to print_r($storenbr);you must use[code]echo "store #: ".$storenbr[0];[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-72748 Share on other sites More sharing options...
VTS Posted August 10, 2006 Author Share Posted August 10, 2006 Ahhhh. Ok thanks alot!! Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-72755 Share on other sites More sharing options...
VTS Posted August 11, 2006 Author Share Posted August 11, 2006 Ok, I have changed that line and now it is not printing anything for it. I also changed another line. I got rid of the mysql_fetch_array() for $sql10 because I want to be able to choose the store number from the store table. Can anyone tell me what I am doing wrong? Here is the new code:[code]$sql = "SELECT COUNT(*) num FROM store WHERE store_open_closed = 'o' "; $result = run_sql($sql) or die(mysql_error()); $storesql = "SELECT store_id FROM store WHERE store_open_closed = 'o' ORDER BY store_id"; $sql10 = run_sql($storesql) or die(mysql_error()); $stores = mysql_fetch_array($result); $x =0; if($x < $stores['num']){ $storenbr = array_slice($sql10,$x,1); echo "store #: ".$storenbr[0]; }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-73094 Share on other sites More sharing options...
sasa Posted August 11, 2006 Share Posted August 11, 2006 try[code]$storesql = "SELECT store_id FROM store WHERE store_open_closed = 'o' ORDER BY store_id";$sql10 = run_sql($storesql) or die(mysql_error());$num_of_stores=mysql_num_rows($sql10);for ($x=0;$x<5;$x++) echo "store #: ".mysql_result($sql10,$x,'store');[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-73107 Share on other sites More sharing options...
VTS Posted August 11, 2006 Author Share Posted August 11, 2006 Still didn't work. I need it to work in an if statement so that I can put some more code in there to display an input page that will cycle one store at a time which is controlled by hitting a submit button. When I use a for statement like that, it just displays it 5 times. But it still didn't display the store number. Thanks for the help though. Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-73119 Share on other sites More sharing options...
sasa Posted August 11, 2006 Share Posted August 11, 2006 i make mistake i echo field 'store' not 'store_id' in line [code]for ($x=0;$x<5;$x++) echo "store #: ".mysql_result($sql10,$x,'store');[/code]corr to [code]for ($x=0;$x<5;$x++) echo "store #: ".mysql_result($sql10,$x,'store_id');[/code]$x is number and you can do any statmens Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-73136 Share on other sites More sharing options...
VTS Posted August 11, 2006 Author Share Posted August 11, 2006 Well I tried that too and still no dice. I really don't have any idea what to do with this. The reason I didn't want to use the for statement is because I need to loop store by store one at a time and not just show them all on one page together. When I use a for or while statment, I cannot get it to just show one store at a time. Rather, it shows them all on the page. My end goal with this code is to be able to have a page where a user is shown the store number and the fields that need to be input for that paticular store and when they hit the submit button, it stores the data in the datebase and then show the fields that need to be input for the next store and so on. Thanks for the quick replies!! Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-73141 Share on other sites More sharing options...
sasa Posted August 11, 2006 Share Posted August 11, 2006 mysql_result($sql10,$x,'store_id') return from resorce $sql10 row: $x and field: 'store_id'when $x=0 it returns 1st row etc. Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-73164 Share on other sites More sharing options...
VTS Posted August 11, 2006 Author Share Posted August 11, 2006 I understand what that statement is saying. What I meant by I don't know what to do with this is that I am stuck and don't know what to do since it did not work. Thanks for all the help. I really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-73166 Share on other sites More sharing options...
VTS Posted August 11, 2006 Author Share Posted August 11, 2006 Anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-73192 Share on other sites More sharing options...
VTS Posted August 11, 2006 Author Share Posted August 11, 2006 I still haven't figured it out...hopefully someone knows what I am doing wrong here. Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-73376 Share on other sites More sharing options...
sasa Posted August 11, 2006 Share Posted August 11, 2006 you need paginationone row per pagegoogle for same tutorial Quote Link to comment https://forums.phpfreaks.com/topic/17177-using-array_slice/#findComment-73385 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.