premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
+1 ++;
-
$usernameFetch = mysql_query("select username from userRegistration where username = '$username'") or trigger_error('Query Failed: ' . mysql_error()); You had an error in your Query, the above should work, for future testing I would suggest to use the trigger_error function so you can see errors as shown above.
-
var_dump. Feel free to consult the manual for function information. As for the loop, look into foreach as that will loop through the array until the array has no more indexes.
-
If/Else statement, different analytics code depending on URL
premiso replied to vitug's topic in PHP Coding Help
Query was meant to be quote, sorry about that my mistake. -
<?php $sql = $query_ps3_list; $qry = mysql_query($sql) or die(mysql_error()); // Cell colors for odd rows $c1 = array('#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e', '#4c4e4e'); // Cell Colors for even rows $c2 = array('#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d', '#5c5d5d'); // Row Counter $cnt = 0; $ret = '<table>'; $i=0; while($row = mysql_fetch_assoc($qry)) { if ($i == 0) { $ret .= '<a href="Test.php?id=' . $row['title'] . '">' . $row_['title'] . '</a>'; $i++; } // Cell counter $cnt2 = 0; $ret .= '<tr>'; foreach($row as $key=>$val) { $ret .= '<td bgcolor="'; if($cnt % 2) { $ret .= $c1[$cnt2]; } else { $ret .= $c2[$cnt2]; } $ret .= '">'.$val.'</td>'; ++$cnt2; } ++$cnt; $ret .= '</tr>'."\n"; } $ret .= '</table>'; echo $ret; ?> EDIT: Added an if inside the loop with $i to increment, if $i is 0 then it adds that code to the list, else it skips it.
-
Multiple Queries - Relationship Question
premiso replied to EternalSorrow's topic in PHP Coding Help
$category = ''; while ($row = mysql_fetch_assoc($result)) { extract($row); // $category = ''; // needs to be outside the loop //Check if the last category output is the same if ($category != $row['category']) { //Assign category to holding var $category = $row['category']; //echo Category heading echo '<h3>'.$category.'</h3>'; } Basically you were reset the $category variable each time the loop ran, that needs to be outside of the loop to work properly. -
That is a LIMIT issue, you need to add that to the query: select t1.author, count(1) as total FROM ( select author FROM author WHERE author <> 'Unknown' UNION ALL select coauthor as author FROM author WHERE coauthor <> 'Unknown' ) t1 GROUP BY t1.author LIMIT 0, 30 Try that and see if that is better.
-
Here is a correction to Mr. Icarus's query: select t1.author, count(1) as total FROM ( select author FROM library WHERE author <> 'Unknown' UNION ALL select coauthor as author FROM library WHERE coauthor <> 'Unknown' ) t1 GROUP BY t1.author That should work.
-
Possible, but would be extremely difficult with a flatfile database. You are better off leaving the log there as the time it would take to open the file find the right IP(s) and overwrite them then save the file, other people could have visited the site and your log file is now out of sync and overwrote other IP logs. If you want that functionality I would suggest going with a Relational Database.
-
If/Else statement, different analytics code depending on URL
premiso replied to vitug's topic in PHP Coding Help
$requested = $_SERVER["REQUEST_URI"]; if (stristr($requested, "query") !== false) { }elseif (stristr($requested, "documents") !== false) { }else { } Would be one way to do it. -
create table secondarytable (rename to what you want) sectblid - primary key / auto inc group lecturer title room mainid - foreign key (added this via an edit.) Which leaves us with: main_table -mainid (pri key / auto inc id for table.) -deptcode -type -dayno -start -finish -weeks Basically, you have a 1 to many relationship between Main table and the secondary table. The secondary table contains the room etc (since you had them labeled as lecturer 1, room 1 module 1, I just assumed that they went together so created a table with them. Other then that it is hard to provide any more structural information to you given that I do not know what type of data goes into the tables etc, but hopefully that gets you on your feet and able to try. I would highly suggest that when you post again, post your current SQL structure you have created, as most people will not want to do this all for you. Learning is trying and asking, so try it and ask if it looks right. EDIT: See comment in psuedo sql structure.
-
Well you can start by posting the line where the error occurs and 5-10 lines around it. (5 above it and 5 below it). Without seeing the actual code we cannot help you.
-
Ummm no it doesn't. You can define a function anywhere on the page and PHP can call that function just fine anywhere on the page. Functions are put into memory before the script is ran.
-
How to save form data and then re-populate on "submit"
premiso replied to mbrittb00's topic in PHP Coding Help
PHP is CaSe SenSitIvE: <?php echo $_SERVER['PHP_SELF']; ?> Would be the proper way to call that variable. -
Nice, did not know you could do that That is probably better then my way. Good work!
-
Any column that is repeating can be it's own table and in that table you would have a common foreign key linking to your main table (the auto increment id of your main table should be used as the foreign key). Since this does seem like homework that is about as far as I will go.
-
Not sure if this is the best way to do it, but here is one way by using a subquery: SELECT author, (SELECT COUNT(coauthor) FROM library au WHERE au.coauthor = at.author) + COUNT(author) AS NumCount FROM library at GROUP BY author;
-
Oh wow, didn't even notice that lol. Thanks!
-
lol because I did not think to look at that and I thought it would be fun to write a function, but yea. That is definitely the better solution!
-
One way to do it: <?php $string = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; echo breakString($string, "<br />\n", 15); function breakString($string, $delimeter = "<br />\n", $breakAt=15) { $breaks = ceil(strlen($string) / $breakAt); // break every 15 characters $newString = ""; for ($i=0; $i<$breaks; $i++) { $newString .= substr($string, ($i * $breakAt), $breakAt) . $delimeter; } return $newString; } ?> EDIT: Made it into a function.
-
The difference in loading you probably will not notice a difference (it is such a small difference), but the .html should load faster due to the simple fact it does not have to run any code it just has to display the html. This is all given that you do not have your server setup to parse .html as .php.
-
I take it that you are looking at the tmp directory of PHP through filezilla, if so, the reason you cannot see the file is it is being moved and or deleted after the script is done processing. PHP only stores the file temporarily for the duration of the script life or until it is moved. Once the script ends, if the file was not moved it is deleted.
-
As to why the ORDER BY does not work: And sorry for moving the topic, I did not know that you were trying to make an array and sort it that way so here goes my attempt to help ya. I am taking that your dates are not in a timestamp form, (this is just a rough design if you want it done better, please post the array data inside of tag from a print_r). [code]<?php function datediff($a, $b) { $a = strtotime($a); $b = strtotime($b); if ($a == $b) $r = 0; else $r = ($a > $b) ? 1: -1; return $r; } $events = array(1 => array("Some Title", "10/24/2009", "etc", "etc"), 2 => array("Other TItle", "11/25/2009", "etc", "etc"), 3 => array("3rd Title", "6/5/2009", "etc", "Etc"), 4 => array("4th Title", "7/4/2009", "etc", "etc")); $dates = array(); foreach ($events as $id => $subArr) { $dates[$id] = $subArr[1]; } uasort($dates, "datediff"); foreach ($dates as $key => $val) { echo "Event Title: " . $events[$key][0] . " on date: " . $val . "<Br />"; } ?> Hopefully that helps you some, if you have any questions on how / why I did certain items let me know!
-
You may be interested in this OLD OLD thread: http://www.phpfreaks.com/forums/index.php/topic,132729.msg558095.html#msg558095 It has some interesting information regarding print vs echo. EDIT: The basic gist, echo tends to be faster and better then print. But it really does not matter which you use as the difference is very minor. It all depends on user preference
-
Rising of oceans now apparently caused by god's tears..
premiso replied to 448191's topic in Miscellaneous
Now that made me laugh. (The Gatorade comment) As far as the nuclear energy, yea. It may sound like a "dumb" idea right now and impossible, but who knows what discoveries are to come. Just like everyone knew the world was flat...I am not saying I can or even know the basics of nuclear energy, I am just saying it could be a viable alternative to look into, how it can be done sure beats the hell out of me cause I am not a nuclear scientist, I was just simply stating an idea/opinion based on very minimal knowledge. Thanks for trying to make my ass sore with those replies though, it was starting to feel less irritated lately.