
Mutley
Members-
Posts
765 -
Joined
-
Last visited
Everything posted by Mutley
-
Thanks alot. If I just wanted to print one, say the 3rd highest number, how would I do that? Would I place [1] [2] etc in the [] and print it that way?
-
I have some numbers: $a = '26'; $b = '25.5'; $c = '24'; $d = '14'; ...etc What I wish to do, is for every .5 = 1 second from the highest number. So, since $a is the highest number, I want it to echo something like this: 0s +1s (this is $b) +4s (this is $c) +24s (this is $d) if that makes sense? Thanks.
-
The problem with doing == NULL for each one is that it takes too much code, can't I just do == NULL once? And just list them.
-
Is it possible to check multiple variables in an IF statement at once? Like instead of doing: if($this == NULL || $that == NULL || $thing == NULL) todo something like if($this, $that, $thing == NULL) Thanks.
-
[SOLVED] help displaying categories w/ subs
Mutley replied to tryingtolearn's topic in PHP Coding Help
You could do it in 2 select queries. If I understand you correctly, something like: <?php $result = mysql_query("SELECT id, title FROM table WHERE parent = '0' "); while($row = mysql_fetch_array( $result )){ $id = $row['id']; $title_parent = $row['title']; } $result2 = mysql_query("SELECT title FROM table WHERE id = '$id' "); while($row2 = mysql_fetch_array( $result2 )){ $title_sub = $row2['title']; } echo $title_parent;// The parent echo $title_sub;// The parents subcategory ?> I hope that makes sense, the first query selects the parent and creates it into a variable, so the next query can use that variable to find all subcategories of it. -
Some people are taking this seriously, lol, come on guys, rename it! I think there should be a Poll.
-
Awesome, thanks!
-
How would I do a where clause? They are INT, the 00 was just an example to stand out. I want to update it like this: $sql = "UPDATE table SET "the field" = '999' WHERE "the fields" = '4'; So it has to find the "4" in the 4 different fields (only 1 field will contain it, it's unique, like a user_id) then change it. Hope that makes sense.
-
So your saying it's an odd title but shouldn't be changed because current users might get confused. I never read the forum descriptions. It's like magazine covers, book covers and DVD covers, your first impression is the title, not the descriptive text on the back.
-
Would I do it using LIKE or AND etc?
-
I use " when doing things like echo/text, then ' for variables, numbers and whatever else. Not sure why, just looks tidy.
-
It's a database. I have a terrible feeling this is going to be a really easy/obvious solution.
-
Is it possible to do a WHERE statement over several fields, so... field1 = 3 field2 = 4 field6 = 9 field0 = 1 Then... $sql = "UPDATE table SET "the field" = '00' WHERE "the fields" = '4'; Result... field1 = 3 field2 = 00 field6 = 9 field0 = 1 Thanks.
-
At the moment I use "INT" for storing 1 and 2 digit numbers. Is this right? Someone said about FLOAT, how does this differ? Thanks.
-
It took me a while to find this are for what it is. "Miscellaneous" to me doesn't really yell out "Off-topic", the area is rather empty, maybe something a little more friendly like "The Lounge" or just "Off-Topic Banter" would be more appealing?
-
My array: $pos_array = array( 0 => array("p1_pts" => $pts_1, "user_id" => "$p1_id", "pos" => 0), 1 => array("p2_pts" => $pts_2, "user_id" => "$p2_id", "pos" => 1), 2 => array("p3_pts" => $pts_3, "user_id" => "$p3_id", "pos" => 2)); How would I do a Foreach on a long array like this? I know the basic ($pos_array as $x => $y) but not anything bigger. Thanks
-
I would do it something like this: table news_stories: id | page_id | author_id | title | story table news_comments: id | news_id | author_id | comment So a page could be in the URL: news.php?page=1 news.php?page=2 ...etc Then $_GET['page'] sets up the query to select the news articles on that page and for comments you would do select all the comments where the news_id = id (the news article id) Just brief but I hope that makes sense. 2 tables seems sufficient. (I would avoid a table for each page).
-
When you upload 1 images, does it matter which form you use, image1 or image2? Do they both work when uploading 1 image?
-
[SOLVED] Attaching variables to a database positioning calculation :S
Mutley replied to Mutley's topic in PHP Coding Help
As an example, how would I get the users id for position 3rd? Is that like doing $id['3rd'] sort of thing, with $position[$id] it's doing something like:- Find that position for this ID? I've puzzled myself now on the whole array/variables. -
[SOLVED] Attaching variables to a database positioning calculation :S
Mutley replied to Mutley's topic in PHP Coding Help
What do you think the array is, if not variables? With the array though using FOREACH, I can only use it in those enclosed brackets can't I? -
[SOLVED] Attaching variables to a database positioning calculation :S
Mutley replied to Mutley's topic in PHP Coding Help
Displays: Code snippet: <?php $pos = 0; foreach ($results as $id => $pts) { $name = ' $_' . ordSuffix(++$pos); echo $name. ' = ' . $id . '<br />'; $$name = $id; // or $$name = $pts; } function ordSuffix($n) { $str = "$n"; $t = $n > 9 ? substr($str,-2,1) : 0; $u = substr($str,-1); if ($t==1) return $str . 'th'; else switch ($u) { case 1: return $str . 'st'; case 2: return $str . 'nd'; case 3: return $str . 'rd'; default: return $str . 'th'; } } //echo '<pre>', print_r($results, true), '</pre>'; echo '1st:' . $_1st; ?> Variables still broken. -
[SOLVED] Attaching variables to a database positioning calculation :S
Mutley replied to Mutley's topic in PHP Coding Help
Still doesn't work sasa. Thanks Barand but I really need them to be set as variables so I can use them for different things. Here is my code: <?php $row = array ( '3', '9', '1', '7', '10', '6', '8', '4', 12, 15, 16, 18.1, 18, 5, 24, 9 ); $id_array = array_slice ($row,0,; $pts_array = array_slice ($row,8,; $results = array_combine ($id_array, $pts_array); arsort ($results); $pos = 0; foreach ($results as $id => $pts) { echo ' $_' . ordSuffix(++$pos) . ' = ' . $id . '<br />'; } function ordSuffix($n) { $str = "$n"; $t = $n > 9 ? substr($str,-2,1) : 0; $u = substr($str,-1); if ($t==1) return $str . 'th'; else switch ($u) { case 1: return $str . 'st'; case 2: return $str . 'nd'; case 3: return $str . 'rd'; default: return $str . 'th'; } } echo '<pre>', print_r($results, true), '</pre>'; $test = $_1st + $_2nd; echo $test; ?> It displays: Using the variables like that sasa, still won't work but if they did that's exactly how I want it! Thanks a lot so far. -
[SOLVED] Attaching variables to a database positioning calculation :S
Mutley replied to Mutley's topic in PHP Coding Help
If I add a "$" to that though, it lists them as text rather than creating them as variables. I need to use the $1st, $2nd etc later on to message each user which position they came among other things. Many thanks so far Barand! -
[SOLVED] Attaching variables to a database positioning calculation :S
Mutley replied to Mutley's topic in PHP Coding Help
Thank-you Barand. Now, to attach a variable (or extract the user_id depending on position) how do I do that? I tried: foreach ($results as $k => $v) { echo "[$k]<br />\n"; } (won't show results if I remove square brackets []) Which works but I get it like: I need it to be like: So, if I made another array to do the 1st/2nd/3rd etc, I can do something like: echo "$$place = $k<br />\n";