how can you this with php and mysql?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scheinarts
Forum Commoner
Posts: 52
Joined: Wed Jul 25, 2007 2:37 am

how can you this with php and mysql?

Post by scheinarts »

scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi guys... today I came up with this challenge, and after a few hours I couldnt come up with an answer... So I hope someone can shed some light. 

I am populating a <select> field with javascript going through a for loop for someArray that holds the values to be populates. In turn, this javascript array variable was populated by php reading from a mysql database... like this.. while(query stuff){<option>mysql values</option>}. No problem until here.

In the mysql database i have 2 tables: clients and shipping_instructions. So here, one client have have many shipping instructions.

I am already populating a javascript called clientsArray with the data from the mysql query. Now I need to dynamically create and populate one a javascript array for each client so that it holds all the shipping instruction values for that client... like this...

[syntax="javascript"]ClientOneArray = new Array("454rr54r", rr4r544r", 6y7y6yy7");

ClientTwoArray = new Array("454rr54r", rr4r544r", 6y7y6yy7");

ClientThreeArray = new Array("454rr54r", rr4r544r", 6y7y6yy7");
The weird looking values are fictional shipping instruction numbers that exist for that client.

How would I set up the mysql query to populate those values for every client.

NOTE - Obviously in the shipping_instructions table each record has the client id so thats how I join the tables

I would really appreciate any input on this... One million thanks!


scottayy | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Are you needing help with the query? Or how to join tables? Or writing the results into a javascript array?

What have you tried, and what were the results?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
scheinarts
Forum Commoner
Posts: 52
Joined: Wed Jul 25, 2007 2:37 am

Post by scheinarts »

Hi! Sorry about that... since it wasnt really code... just some pseudo code i came up with.

I am needing help with the query and the while loop that will dynamically create those javascript arrays... You see, the problem is that I am only getting ONE shipping_instruction per client, when in fact each client has numerous shipping instructions.
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

Post by devendra-m »

scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<?
	$shipping_instructions[0]=array('ab','bc','dv');
	$shipping_instructions[1]=array('re','bg','ok');
	$shipping_instructions[2]=array('tr','wq','lk');
	$shipping_instructions[3]=array('uh','df','gh');
	$n=4;
	foreach($shipping_instructions as $key=>$value)
	{	
		$shipping_instructions[$key]=implode(',',$shipping_instructions[$key]);
	} 

?>

Code: Select all

<script>
function test()
{
	<?
for($i=0;$i<$n;$i++)
{
	
?>
eval("client<?=$i?>=new Array(<?=$shipping_instructions[$i]?>)");

<? }
?>
	
}
</script>

scottayy | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by devendra-m on Tue Dec 04, 2007 12:38 am, edited 1 time in total.
scheinarts
Forum Commoner
Posts: 52
Joined: Wed Jul 25, 2007 2:37 am

Post by scheinarts »

hmmm... Is $n the number of shippings instructions for all clients, which could be thousands, or the just the number of shipping instructions for one client?

The thing is getting all the shipping_instructions for one customer and their could be hundreds of customers. So php has to echo hundreds of javascript arrays each containing all the shipping instructions for each client. Then name of these created arrays should be for example

Code: Select all

$clientName . "Arr"
Post Reply