
gr1zzly
Members-
Posts
48 -
Joined
-
Last visited
Never
Everything posted by gr1zzly
-
Okay so I'm just a newbie here and may not fully understand the workings of this forum (appologies), and indeed only started teaching myself php about a month ago, but I have a suggestion... What if people who post 'Help needed' topics could indicate exactly which user's response helped them to solve their problem? This could then be turned into a sort of rank for the users based on their successful helps, not just how many posts they've made. As it stands it seems that people are kind of ranked based on their 'presence' on the forum, i.e. how many posts they've made. But this doesn't necessarily have any bearing on the persons actual ability. My suggestion would provide a 'Quality over Quantity' approach to users advice. What are people's thought's on this?
-
It is common practice to contain any sensitive data (such as usernames and passwords for database connection) in a separate file stored outside of the public_html folder (making it inaccessible from a web browser) then referencing that from the file you need to use it with via a require_once() statement. Would this approach work? Note: There may be some settings in php.ini relating to calling scripts outside of the public html folder, but I am not certain on this, best to check the manual (or Google). Also it's best to use absolute referencing for folder/file addressing.
-
PHP MYSQL remote connection --please help
gr1zzly replied to worldcomingtoanend's topic in PHP Coding Help
I would actually point to the first response from MrAdam. It seems to me like your assigning the database name twice! Passing your $mysql_database variable once as a parameter in the mysql_connect() statement should be enough. Only if you're connecting with just the host, user_name, password would you then need a separate mysql_select_db() statement AFAIN. I can post an example of the script I use to connect if that will help? -
Sorry I made a mistake before in addressing the array, the $i is not required -> just use the square brackets to assign a row... while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC) ) { $data[] = $row; }; Like so! Then when you come to address the variable later a simple foreach ($data AS $row) { // Something to do with the data... } in this foreach() the $row is the whole row from the database as an associative array (depending on the query and results fetch method of course) and so can be addressed as $row[column_name], where 'column_name' is the name of the column you want the contents of. Hope this helps.
-
Since you want the ampersand in this case to be a part of the string "Conor Oberst & The Mystic Valley Band" you need to escape this character in some way so that it is not treated as part of the query and simply as part of the string to be returned. I'm not an expert so I don't know if the standard escape character ' \ ' (before url encoding) would work or if there is some other way to prevent this character from being encoded into it's url form.
-
You may want something more like this... SELECT user_email FROM mytable LIMIT 100 OFFSET $offset; LIMIT tells how many records to retrieve and OFFSET which record no. to start from. Then just increment $offset for each exec of the query. Also, forgive me if this is irrelevant, but do you need to retrieve all columns values ( i.e. ' * ' ) for each row or just one or two specific fields? You can select more than one specific field by separating them with a comma.
-
PHP MYSQL remote connection --please help
gr1zzly replied to worldcomingtoanend's topic in PHP Coding Help
Assuming that your connection data is correct for your specific server i.e. host name, user name etc. Try using an if condtional instead of a switch statement. Something like: if ($link) { echo "<h1>Connection successful</h1>\n"; } else { echo "<h1>Connection failed!</h1><br/>Debug: " . mysql_error($link) . "<br/>\n"; } -
[SOLVED] Object of class mysqli_result could not be converted to string
gr1zzly replied to gr1zzly's topic in PHP Coding Help
Thanks again for the help on the quoted topic, sorry again for the hijack (and my newbieness). Hope that this solution may help others. >To Moderator - Could you change the title of this topic to something more suitable and search friendly such as "Storing multiple SQL results in an array variable" or something, please? Thankyou -
Ok I think I've got it working now. Sorry I wasn't fully understanding how to use the results with an array variable. I am now using the following: $r = @mysqli_query($dbc, $q); // OR $errors = mysqli_error($dbc); if ($r) { // If OK. $i = 0; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC) ) { $data[$i] = $row; $i++; }; return array(true, $data); } Using the extra $i var to reference the $data array allowed me to create an array entry for each row as a sub array containing all the rows cell data. Thanks to all your helps.
-
okay, please forgive my ignorance / stupidity but which part exactly? I literally have tried all kinds of different while and foreach loops and combinations so if the code I have now has got a bit lost somewhere I apologize. What I need is each whole row of results to be stored associatively in my $data array variable as one entry. So that each entry in $data is an associative array containing one row from my db.
-
With regards the 'error message' red border being added, afain php cannot manipulate DOM elements or the styles associated with them once the element has been generated. If the page is to be re-generated by php after each submit attempt you can use conditionals to create the form's elements with the appropriate styles (such as border colour etc.) pre-applied. The only other way I can think of is to use Javascript to perform the validation and alter the form element's styles through DOM CSS manipulation, using AJAX to call the php function if everything's ok and passing the form fields as variables. Downside of Javascript is it is client side and therefor could be disabled on the user's machine. Web design accessibility standards prefer functionality to be as non-dependent on potentially absent technologies as possible, or at least provide alternative means to perform the same function (usually at the expense of the 'pretty' things). In your case this would mean no red borders, but you could still echo out an error message text for php only functionality.
-
Google solves soooo many woes, check out http://www.w3schools.com/PHP/php_file.asp or http://php.about.com/od/advancedphp/ss/file_write_php.htm ...literally tons of examples / tutorials out there
-
Form help - being able to duplicate form components
gr1zzly replied to mdemetri2's topic in PHP Coding Help
Create a function that simply prints the required form fields and call that function every time the 'add question' button is clicked. Something like: function add_form_elements ($vars, $if, $required) { echo "<select name=''>"; # populate 'option' fields from db echo "</select><br />\n"; echo "any additional form elements required"; Maybe auto numbering each form element so that you can keep track of how many results are being read back when the form is submitted! * Note - You could also use javascript to reproduce the form elements if you prefer, not sure if benefits vs php? -
How do I search a 2d array, with x and y being variables
gr1zzly replied to artoak's topic in PHP Coding Help
Can you please clarify your meaning here? - Do you want the POST variable to be a limiting factor in the query or simply have the relevant (i.e. direction) contents of a row output to the 'field 4' form element? - Or something else entirely. Also using more descriptive names than 'Filed 4' etc. would really help. Even if you know what they are now it's not clear to us, plus if you come back to the script at a later date will you still remember? Safer just to use clear naming of all elements. -
Hey, sorry to hijack your post but I'm having a similar problem and urgently need help. Posted here but no replies yet - link below: http://www.phpfreaks.com/forums/index.php/topic,268388.0.html Surely someone on here knows how to use foreach's with mysql results objects? Thanks
-
[SOLVED] Object of class mysqli_result could not be converted to string
gr1zzly replied to gr1zzly's topic in PHP Coding Help
Ok, so now I've got text to output, but it's just printing the same post over and over!! The $data variable is definitely being set to an array properly, but it seems like it's only storing 1 row from the db with each column in the row being stored as a separate entry. What i need is each whole row being put into $data as 1 entry in an associative manner. So i'm guessing making it a 3 dimensional array where each entry in $data is a sub array for each db row, stored as 'column' => 'value'. 1. How do I achieve this? Next I pass $data back with the return() function and iterate through each entry with a foreach statement ( see 1st post ). 2. How do I use foreach in conjunction with a 3D array? Help please as I really need to get this working before I can move on with this project. -
I've had similar questions with my first serious php project, a blog style site with a mini bespoke content management system. Best to use php's built in function strip_tags() although htmlentites() will render any html inert. Here''s a really helpful guide for security issues http://php.robm.me.uk/
-
[SOLVED] Not a problem, just an explanation needed really.
gr1zzly replied to berridgeab's topic in PHP Coding Help
I'm not sure about the parsing but my guess is that it will parse all of the code. Seems to me like you have a better method already. If you do the select case to include() the script for each page as it's required not only will you compartmentalize your scripts making them easier to manage and update but the parsing issue becomes moot. -
Unable to Upload Files: Suggestion / Help needed
gr1zzly replied to gcreddy's topic in PHP Coding Help
http://www.tizag.com/phpT/fileupload.php or try google ? !! -
Okay so my understanding is that you want the page to scroll to the anchor after it's been compiled by php. Yes? I'm not an expert but it sounds as though you need a client side function to interact with the page once it's been generated. This ( afain ) cannot be done with php which is sever side, you should try javascript or something that works on the client side. Mootools has a nice smooth scroll function in it's 'More' module. http://mootools.net/
-
Ok, hard to understand this but here goes... If you need a 'dropdown box' then why not use the html form <SELECT> element and if no db access is required why not just hard code the menu with html? Of course if you wanted you could use php to output the select menu by doing something like echo "<select name='a_name'>"; then as play_ suggested use a FOR or FOREACH loop to write out the options, e.g. for ($i = 1; $i <= 7; $i++) { echo "<option value='day_value'>Day Name</option>"; } </select> but the effect is the same so why bother using php unless you have to, like if it absolutely needs to be sever side or if it offers function that you cannot provide using basic html and/or javascript!
-
Ok so I have a script for paginating results on a blog style site, only I can't get the posts to output properly to the page. The web page includes() the "populate" script which itself then requires_once() the "populate_functions" script file. The populate script calls to the print_page() function which in turn calls to the get_rows() function which access the database and retrieve the posts. But I can't get the results array to return back to the print_page function properly. At first I tried just returning the results object variable ( $r ) which gave me the error shown in the tittle of this post. I have also tried reading $r into another variable e.g. $row = mysqli_fetch_array($r, MYSQLI_ASSOC); return array(true, $row); as well as trying to read it into an array variable using $row = mysqli_fetch_array($r, MYSQLI_ASSOC); foreach ( $row AS $rec ) {$data = $rec;}; return array(true, $data); the most I have got for my efforts has been single letters or numbers instead of the full text of post titles, dates and text etc or the error "Invalid argument supplied for foreach() in /php/populate_functions.inc.php on line 125". The actual output function works as follows: list ($chk, $data) = get_rows($dbc, $table, $is_sticky, $limit, $offset); // Retrieve posts. if ($chk) { // Got posts OK! echo "<h4>Step 6 : Printing posts where Sticky = {$is_sticky}!</h4>"; ### DEBUG ### echo "<p>{$data}</p>\n"; ### DEBUG ### foreach ($data AS $row) { if ( $rows_left > 0 ) { echo "<div class='{$table}_post is_sticky'>"; if ($row[is_sticky] == 1) echo "<p><b><i>Sticky</i></b>"; echo "<span class='post_date'>Posted: '" . $row[post_dts] . "'</span></p> <h4>'" . stripslashes($row[post_title]) . "'</h4> <p>'" . stripslashes($row[post_text]) . "'</p> <p class='post_foot'>Posted by: '" . $row[post_auth] . "'</p> </div><br />\n"; }; $rows_left = ($rows_left - 1); }; // End of FOREACH. } else { // Get posts failed! // Print errors? }; // End of GET POSTS. Any ideas what I'm doing wrong, I am new to php so go easy on me please if it's a simple stupid mistake. Thanking you in advance for your helps