ober
Staff Alumni-
Posts
5,327 -
Joined
-
Last visited
Everything posted by ober
-
1) What resolution are you designing for and is it fixed? Resizing my browser window didn't affect the website at all, which is normally fine, but it appears you have it set for a 1280x1024 resolution... that's high for the majority of your users. 2) The scrolling banner image is both annoying and unecessary. You could achieve the same results with a static image. 3) You might have wanted to finish up the menus before posting it here, as it's hard to tell what the final product is going to look like on the left. 4) The black titles that show up inside your little blue gradient boxes are hard to read.... black text on dark blue? Are you serious? That was just a quick look... let us know when you have more done.
-
Hmm... wasn't me. EDIT: Does appear to be working fine, however.
-
Umm... yeah, suprisingly enough with the name change, people still post PHP questions here. WTF? Thread Moved.
-
Ask ONE QUESTION to determine if someone is a good programmer
ober replied to sharkyJay's topic in Miscellaneous
That's ridiculous. You cannot determine a programmer's worth on one question. That's a management pipe dream. -
Welcome to the PHPFreaks forums!
-
All depends on how you set it up. The normal ways it to have different levels for different members. If the user is above a certain level, show them the link, if they're not, hide it.
-
As some of you have noticed, the PHP Newbie forum has disappeared. In an effort to streamline the forums and provide the fastest response and best experience, we've combined the 2 main PHP boards. We've also created a new READ-ONLY boards for the members where we have posted numerous questions that are asked here all the time. We'll be adding to this and editing it over time. If you have a question and think it's come up before, PLEASE check there first! Link! [a href=\"http://www.phpfreaks.com/forums/index.php?showforum=41\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showforum=41[/a] We're also working to add more features and make the site a little faster and more user-friendly. Stay tuned for more updates and thanks for being part of a great community!
-
What happened to the Newbie forum???
ober replied to kenrbnsn's topic in PHPFreaks.com Website Feedback
I should add that we have the code to return the PHP tags and the Solved button. It just has to be verified, tested, and installed. -
NOTE: This information is now obsolete, as the mysql_ functions are deprecated and have been removed from PHP as of php5.5. Use the mysqli or PDO_Mysql extensions instead. MySQL Data Retrieval A very common problem I see on these forums is that some people are not checking for errors after an SQL query. You need to check for a good return (no errors) before performing any subsequent SQL related commands (such as a fetch or number of rows). Also, you must check if you got data back after attempting to retrieve the data; do not just start using the row data blindly. Good coding practice never assumes there will be data returned. Example: // Connect to MySQL server first – You can use variables instead of these literals $db = mysql_connect('localhost', 'username', 'password'); if (!$db) { echo 'Could not connect to MySQL server. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } // Select the database you want to use – You can use a variable here too instead if (!mysql_select_db('DBname', $db)) { // Did selection fail? // Handle error echo 'DB Selection failed. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } // An example for retrieving zero or more rows $sql = "SELECT name, email FROM people_table"; $result = mysql_query($sql, $db); if (!$result) { // Handle error echo 'Query failed. SQL: ', $sql, '<br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } // The while loop stops when there's no data left; it might not even go in loop // and echo anything when there's no data returned on the first call to // mysql_fetch_assoc() while($row = mysql_fetch_assoc($result)) { // Retrieve data until no more echo $row['name'], '<br />'; echo $row['email'], '<br />'; } // Optional – Free up memory. Done automatically when script ends if (!mysql_free_result($result)) { // Handle error or ignore it echo 'Freeing results failed. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } // Once the results table is freed, don't attempt to use the $result variable anymore //**************************************************************** // For retrieving zero or one row (the first row with that name) $name = mysql_escape_string('John Doe'); // or use addslashes() $sql = "SELECT email FROM people_table WHERE name = '$name'"; $result = mysql_query($sql, $db); if (!$result) { // Handle error echo 'Query failed. SQL: ', $sql, '<br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit; } $row = mysql_fetch_assoc($result); // Try to retrieve the data if (!$row) // No data returned? // Not necessarily an error – Just no data matched search criteria echo 'No data found <br />'; else // There is valid data returned echo "The email for $name is ", $row['email'], '<br />'; // Optional – Close MySQL connection. Will be closed at end of script anyway // Do NOT put a mysql_close() after a query and before fetching data! if (!mysql_close($db)) { echo "Couldn't close database <br />"; // or ignore error exit; } Note that some people use die(), which is simply an alias of exit(). I've also seen this type of poor coding: $nbr = mysql_num_rows(mysql_query("SELECT name, email FROM people_table")); // or $row = mysql_fetch_assoc(mysql_query("SELECT name, email FROM people_table WHERE id = '$id'")); Never enclose one MySQL function inside another like that. As already explained, a query could return an error and a valid results resource won't exist (or be returned). This would then cause the outer function to fail with a "not a valid MySQL result resource" message (see the Annoying Errors section below). TIP: You can make the formatting of SQL statements a little bit easier by using arrays and the sprintf() function. One array could hold all the column names you have in a table. Like this: $columns = array('catg_id', 'catg_description'); You can even find out what the column names are dynamically and place the column names in an array producing the same result as above. In the following example, the first '%s' in sprintf() will be replaced with '*' and the second '%s' will get replaced with 'categories'. Here's the example: // An example to automatically get column names $sql = sprintf('SELECT %s FROM %s LIMIT 1', '*', 'categories' ); echo 'COLUMN NAME SELECT SQL: ', $sql, '<br>'; $result = mysql_query($sql); if (!$result) { echo 'Query failed. SQL: ', $sql, '<br>Error: ', mysql_error(), '<br>'; exit; } $row = mysql_fetch_assoc($result); // Retrieve the one row if (!$row) // No data found? // Set columns manually or display error (and exit) $columns = array('catg_id', 'catg_description'); else // Convert associate keys into values $columns = array_keys($row); echo '<pre>', print_r($columns, TRUE), '</pre>'; The above code would display something like this: [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]COLUMN NAME SELECT SQL: SELECT * FROM categories LIMIT 1 Array ( [0] => catg_id [1] => catg_description ) [/quote] Inserting data into a table can be easier with having a columns array and a values array. Then using implode() to handle the formatting of commas and generating the SQL. This is especially handy when you have lots of column names in your table. Example: // Escape characters when necessary and surround value with quotes function quote($_value = '', $_check_gpc = TRUE) { if (($_check_gpc) && (get_magic_quotes_gpc())) return ("'" . $_value . "'"); else return ("'" . mysql_escape_string($_value) . "'"); } /* * You can create arrays to hold table and column names */ $tables = array('categories'); // Doesn't have to be an array $columns = array('catg_id', 'catg_description'); /* * Build an array of values to place in table * The order of values needs to correspond to column(s) order given */ $values = array(); // Initialize $values[] = quote(''); // catg_id blank - auto increment $values[] = quote($_POST['catg']); // New category – Contains: Cameras /* * Use sprintf() to nicely take care of building the SQL statement */ $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', implode (', ', $tables), implode (', ', $columns), implode (', ', $values) ); echo 'INSERT SQL: ', $sql, '<br>'; $result = mysql_query($sql); if (!$result) { echo 'Insert failed. SQL: ', $sql, '<br>Error: ', mysql_error(), '<br>'; exit; } $last_id = mysql_insert_id(); // Get last auto increment id used echo 'Last insert id: ', $last_id, '<br>'; Which displays something like this: [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]INSERT SQL: INSERT INTO categories (catg_id, catg_description) VALUES ('', 'Cameras') Last insert id: 1 [/quote] The update SQL is a little trickier because we have two separate arrays that hold the column name and values. You could have one array where the keys of the array are the names of the columns and the values would of course be what you want to update or modify. This sample code uses two separate arrays for column and values. When you're table contains an auto increment column, then you probably don't want to change it's value. So, this code removes it so it won't get updated. See example code: // Returns column_name = 'value' for update SQL function kv_pair($_key = array(), $_value = array()) { $_result = ''; $_key_cnt = count($_key); $_value_cnt = count($_value); if (($_key_cnt > 0) && ($_key_cnt == $_value_cnt)) { $_result = array(); for ($i = 0; $i < $_key_cnt; $i++) $_result[] = $_key[$i] . ' = ' . quote($_value[$i]); $_result = implode(', ', $_result); } return $_result; } $without_id = $columns; // Copy original columns array $id = array_shift($without_id); // Remove first catg_id entry $values = array(); // Initialize $values[] = 'Books'; // Change category description to Books $where = array(); // Initialize $where[] = $columns[0] . ' = ' . quote($last_id); // catg_id = 'last number' $operator = ''; // Just one condition; no need for operator $sql = sprintf('UPDATE %s SET %s WHERE %s', implode (', ', $tables), kv_pair($without_id, $values), // returns a string implode (" $operator ", $where) ); echo 'UPDATE SQL: ', $sql, '<br>'; $result = mysql_query($sql); if (!$result) { echo 'Update failed. SQL: ', $sql, '<br>Error: ', mysql_error(), '<br>'; exit; } The update code displays something like: [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]UPDATE SQL: UPDATE categories SET catg_description = 'Books' WHERE catg_id = '1' [/quote] Generating the select SQL is pretty simple using this method. See example code: $where = array(); $where[] = $columns[0] . ' = ' . quote($last_id); // Need ID or description $where[] = $columns[1] . ' = ' . quote('Books'); // but using both to show AND $operator = 'AND'; $sql = sprintf('SELECT %s FROM %s WHERE %s', implode (', ', $columns), implode (', ', $tables), implode (" $operator ", $where) ); echo 'SELECT SQL: ', $sql, '<br>'; $result = mysql_query($sql); if (!$result) { echo 'Query failed. SQL: ', $sql, '<br>Error: ', mysql_error(), '<br>'; exit; } while ($row = mysql_fetch_assoc($result)) echo '<pre>', print_r($row, TRUE), '</pre>'; The select code above would display something like this: [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]SELECT SQL: SELECT catg_id, catg_description FROM categories WHERE catg_id = '1' AND catg_description = 'Books' Array ( [catg_id] => 1 [catg_description] => Books ) [/quote] Here's an example of a select SQL using two tables: $tables = array('categories', 'inventory'); $columns = array('catg_id', 'catg_description', 'inv_in_stock', 'inv_description', 'inv_price'); $where = array(); $where[] = $tables[0] . '.' . $columns[0] . ' = ' . $tables[1] . '.' . $columns[0]; $where[] = $columns[1] . ' = ' . quote('Books'); $operator = 'AND'; $columns[0] = $tables[0] . '.' . $columns[0]; // make into categories.catg_id $sql = sprintf('SELECT %s FROM %s WHERE %s', implode (', ', $columns), implode (', ', $tables), implode (" $operator ", $where) ); echo 'SELECT SQL: ', $sql, '<br>'; $result = mysql_query($sql); if (!$result) { echo 'Query failed. SQL: ', $sql, '<br>Error: ', mysql_error(), '<br>'; exit; } while ($row = mysql_fetch_assoc($result)) echo '<pre>', print_r($row, TRUE), '</pre>'; The select code above would display something like this: [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]SELECT SQL: SELECT categories.catg_id, catg_description, inv_in_stock, inv_description, inv_price FROM categories, inventory WHERE categories.catg_id = inventory.catg_id AND catg_description = 'Books' Array ( [catg_id] => 1 [catg_description] => Books [inv_in_stock] => 10 [inv_description] => Setting Up LAMP: Getting Linux, Apache, MySQL,and PHP Working Together [inv_price] => 34.99 ) [/quote] Acknowledgement: toplay.
-
NOTE: This information is now obsolete, as the mysql_ functions are deprecated and have been removed from PHP as of php5.5. Use the mysqli or PDO_Mysql extensions instead. MySQL Data Retrieval Q: I have inserted the data into a MySQL database, but how do I show it? (I sometimes get "Resource id#") A: To do this, you should use mysql_fetch_array, or in many cases, mysql_fetch_assoc. The first one obtains an array where you can either use the column name, or a row number. Since I don't think in numbers, I use the second one, which only obtains an array of the column names. More info: [url=http://www.php.net/mysql_fetch_array]http://www.php.net/mysql_fetch_array[/url] [url=http://www.php.net/mysql_fetch_assoc]http://www.php.net/mysql_fetch_assoc[/url] To do this, let's assume you have a query set up. In this case, an example would be: $sql = "SELECT name, email FROM people_table"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)){ echo $row['name'].'<br />'; echo $row['email'].'<br />'; } The while() loop will go through all the data in the table, and when it reaches the end (when there's no more data to go through), it will stop. Notice how the declaration of the $row variable is not used with the equality operator, ==. Acknowledgement: steveo31
-
[b]Q. How can I force download of files?[/b] A. I found this snip of code and it looks promising. [code]<?php // force to download a file // ex, ( [url=http://localhost/php/download.php?file=C:/Apache]http://localhost/php/download.php?file=C:/Apache[/url] Group/Apache2/hongkong.php ) // hope this can save your time :-) $file = $_REQUEST['file']; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header( "Content-Disposition: attachment; filename=".basename($file)); header( "Content-Description: File Transfer"); @readfile($file); ?>[/code] This hasn't been much of a common question, but it is helpful nontheless. [b]MODIFICATION 6/23/06[/b] Just above the @readfile, addition of the following code will inform the browser of what's coming -- allowing it properly report download progress and estimated completion time. [code] header('Accept-Ranges: bytes'); header('Content-Length: ' . filesize($file)); [/code] Acknowledgement: steveo31, michaellunsford
-
[size=3]Annoying Errors[/size] [quote]Warning: main(): Failed opening '/home/the-whom/public_html/layout.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/the-whom/public_html/join.php on line 2[/quote] [b]Solution:[/b] Make sure that the file you are trying to include() is named correctly, and is pointing to the right path, such as [i]include 'includeFolder/file.php';[/i] [quote]Warning: mysql_result()/mysql_fetch_assoc/mysql_num_rows/mysql_fetch_object: supplied argument is not a valid MySQL result resource in /home/the-whom/public_html/join.php on line 78[/quote] [b]Solution:[/b] Check your SQL syntax and make sure that there is indeed a row (or rows) that match the criteria. For example: [code] <?php $sql = mysql_query("SELECT name, id FROM users WHERE name='Jacko'"); //if there is no field called "name" you'll get an error. ?> [/code] [quote]Error inserting your information into MySQL: No Database Selected[/quote] [b]Solution:[/b] Connect to the Database, and if you have connected, make sure that you have selected which DB you want to use with mysql_select_db(). [quote]Fatal error: Call to undefined function: footer() in /home/the-whom/public_html/join.php on line [/quote] [b]Solution:[/b] Make sure the function exists. Acknowedgement: steveo31
-
The only thing I can suggest without knowing more about the project is possibly using AJAX in the background to do some of the updates behind the scenes.
-
If you're not getting the desired results with CSS, I'd suggest that you're probably not using it correctly.
-
[b]Q:[/b] How do I create a multi-column layout for my gallery/store from MySQL results or an array? [b]A:[/b] A lot of times you'll see people suggest using CSS for layouts. This is one time 99% of developers are going to tell you to use a table. [code] <table cellspacing="3" cellpadding="3"> <?php $query = "SELECT product FROM selling_items ORDER BY prod_id"; $result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($product != "" && $product != null) echo "<td>$product</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> </tr> </table> [/code] To modify this for an array, just replace the while loop with a for loop and use your array as the input instead of the mysql fetch results.
-
You do know that you can adjust your site for whatever resolution using CSS, right? That's why you have relative positioning and percentages instead of fixed values. And what if someone comes to your site with Javascript turned off? What happens? I'll tell you... your site is completely unusable.
-
That's fantastic.... want to point out to the person WHERE you found these errors and what they were???
-
It's better... not great. I don't understand whether you're trying for a full-width site or a fixed-width. Your content is centered and fixed-width, yet your header and footer are full-width and not centered. It looks very odd at large resolutions. I also don't get the need for internal scrolling. I never did on any site. That forces me to use your scrollbar instead of the browser's. I think your nav font size could be a tad smaller. It's huge right now. It is also VERY hard to read red on that god-awful green color you're using in the news section. The news section is also very choppy and random... it doesn't have a good flow to it. Also keep in mind that text wasn't meant to be read against a dark background! It's hard on the eyes.
-
Threads merged... no point in having another thread.
-
What happened to the Newbie forum???
ober replied to kenrbnsn's topic in PHPFreaks.com Website Feedback
It has been combined with PHP Help. The seperation was minimal at best and we thought it was easy enough to combine the 2. -
This is a new board with the intentions of reducing repeating questions. All of the topics in this board have been asked dozens if not hundreds or thousands of times. Some of the these topics are even covered in tutorials on the main website (http://www.phpfreaks.com/tutorials.php). If you know of any additional material that needs to be put in here, PM myself or steelmanronald06 and we will see that it gets added in one fashion or another. Thanks for reading and good luck in all your coding endeavors!
-
You're right on the first part... but you use =="" to see if a field is empty or not.
-
No need to remove it... just post here again when you're done. And I was using Opera and Firefox. Both looked the same.
-
isset vs. == "" are 2 entirely different things... I thought I made that clear. isset checks to see if the variable has been created at all. checking to see if it is equal to an empty string just does exactly that. Do you see the difference??
-
Well... I looked at in Opera and thought it must be just Opera that's screwing it up, so I opened it in Firefox just to see... and yeah... it's really THAT ugly. Wow. No offense, but no one is going to use that with the way it looks. It's disorganized, you use random background colors very poorly, and ... I'm just not sure what to make of it.