
Mutley
Members-
Posts
765 -
Joined
-
Last visited
Everything posted by Mutley
-
Still need to know how to do this with more control over the variables. ???
-
<table width="80%" border="1" cellspacing="0" cellpadding="3"> <tr> <td>id:</td> <td>obja:</td> <td>objb:</td> <td>objc:</td> </tr><tr> <? $result = mysql_query("SELECT * FROM `table`"); $array = array(); while($row = mysql_fetch_assoc($result)) { if(array_key_exists($row['id'], $array)) { $array[$row['id']]['obj1'] .= "/".$row['obj1']; $array[$row['obj2']]['obj2'] .= "/".$row['obj2']; $array[$row['obj3']]['obj3'] .= "/".$row['obj3']; } else $array[$row['id']] = array("obj1" => $row['obj1'], "obj2" => $row['obj2'], "obj3" => $row['obj3']); } foreach ($array as $id => $content) echo "<tr><td>".$id."</td><td>".$content['obj1']."</td><td>".$content['obj2']."</td><td>".$content['obj3']."</td><br>"; ?> </tr> </table> As you see above I'm trying to get each part into columns of a table but with "obj2" it has 2 different numbers which I want in 2 different sections, rather than "5/6" it has those numbers in table columns. I've confused myself now, lol. So if there are lots of '1' in obja, it only displays one, not 1/1/1/1/1.
-
I've got it working thanks. If I wanted to make a new query using one of the variables from that array, how do I do it?
-
Could you help explain what each part does please? I'm not familiar with arrays.
-
I have multiple rows for the same "id", but when I come to display it in a table, it loops the 'id' rows 2 or 3 times, what I want to do is loop each "id" once, so: id:|obja:|objb: 1 | 1/2 | 12/15 2 | 5/6 | 20/30 Instead of: id:|obja:|objb: 1 | 1 | 12 1 | 2 | 15 2 | 5 | 20 2 | 6 | 30 ... But also pull information out of the rows fields for each 'id', is this possible?
-
But if the variables are: $value = '100'; $discount_value = '200'; // Value AFTER discount It does a negative percentage, is it possible to say "200%"? Rather than "-100%".
-
<?php $value = '100'; $discount_value = '80'; // Value AFTER discount ?> What % do they save? How do I calculate this?
-
I've never used a function before. I have a large amount of code about 80 lines and there are only 2 or 3 variables that I need to change. Basicly I want to repeat the code in less than 80 lines, and replace the variables. Can this be achieved in a function?
-
In a text field a visitor can fill in a name, then chose several distances
Mutley replied to YFinn's topic in PHP Coding Help
You could do something like: if(isset($_GET['moth'] && $_GET['1mile']) { ...open page... } For each one but it isn't efficient. -
I got that to work. Can you link to any resources or reply how I would do this without listing the query results, just using something like $row['field'] instead? I've never used the "INNER JOIN" SELECT method before, so not sure how it exactly works.
-
If I take away the echo to make them variables (not displayed as text) I get a unexpected variable message.
-
I got this to work: <?php $count=0; $p1_slot = 'p1_slot'; $sql = "SELECT u.user_id, u.slot, p.name, p.points FROM loadout u INNER JOIN products p ON u.prod_id = p.prod_id WHERE u.user_id = '1' ORDER BY u.user_id, u.slot"; $res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); while (list($user, $slot, $prod, $points) = mysql_fetch_row($res)) { echo "$$p1_slot$count = $points<br>"; $count++; } ?> $p1_slot0 = 3 $p1_slot1 = 5 $p1_slot2 = 4 $p1_slot3 = 4 $p1_slot4 = 10 $p1_slot5 = 3 But if I wanted to use these variables in a part of the script further on, how would I do that? As at the moment they don't show in the code, only when echoed.
-
I receive lots of: 1 1 1 I need it to display the $points with a new variable for it, so it would show as: $newvar1 = $points; $newvar2 = $points; $newvar3 = $points; $newvar4 = $points; But with a loop it would obvioulsy just be 1 of the above but I can't assign variables to it (as it would just loop the same number/variable).
-
Try doing it in HTML: € Rather than a copy n' paste symbol.
-
Doesn't appear to be working, I'm using a looping query list, like this: while (list($points) = mysql_fetch_row($res)) { echo "$points<br>"; }
-
I have a looping database query and want to create a variable for each one, there will only be 6 results from the query. I tried: $number = array(1,2,3,4,5,6); ...{ echo "$variable$number = $database_entry"; } But the array won't work, it's probably obviously wrong to you guys.
-
It works, thanks a lot! Can you explain what the "u" and "p" mean in the query? Like u.user_id and u.slot?
-
What is the best way to redirect to other page?
Mutley replied to anybody99's topic in PHP Coding Help
I use: <script type="text/javascript"> window.location = "page.html" </script> -
Here is an example of a query I'm using with the table I have now for loadout: <?php $result2 = mysql_query("SELECT * FROM loadout WHERE user_id = '$login' LIMIT 1"); while($row2 = mysql_fetch_array( $result2 )) { $l1_slot1 = $row2['slot1']; $l1_slot2 = $row2['slot2']; $l1_slot3 = $row2['slot3']; $l1_slot4 = $row2['slot4']; $l1_slot5 = $row2['slot5']; } ?> So how would this change? If I used your method, wouldn't I have to do a loop query and attach variables?
-
Aha, thanks, fully understand now. All my other tables are already in that format. I'll reply once everything is changed and working with the new table layout. EDIT: If I do it that way though, how do I know what the different slots are?
-
That's what it is, except in "loadout" I don't have the "id" column.
-
This is slightly complicated to what I'm used to. So do I need to create a new column in loadout for something? I don't understand what your diagram is explaining. Thanks a lot for your help so far.
-
Ahh, sorry, I got it wrong. What I have is: Table: loadout user_id | slot1 | slot2 | slot3 | slot4 | slot5 The "slots" have the product id's in. Then, Table: products prod_id | name So I want to create a list for that user, by getting the name of the products from the prod_id in the "slot" fields.
-
How would I use that in PHP? Via phpmyadmin I get: