-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
Hmmm.... For a 'newbie' this is an awfully complex design you are working on. May I ask how you got yourself into this pickle?
-
PHP $this->_vars['HTML'] unknown missing value [closed]
ginerjm replied to THEJOKERRED's topic in PHP Coding Help
As was pointed out in your previous post. Take a look at other posts on this forum (and others) to see how most people write their code. -
And turn on php error checking - it will probably point out the error GW has diagnosed with a line number
-
The answer is to use a recursive function. Run this: $array1 = array( 'key'=>'value', 'key2'=>'value2', 'key3'=>'value3', 'arr2'=>array( 'subkey'=>'subvalue', 'subkey2'=>'subvalue2' ), 'key4'=>'value4', 'arr3'=>array( 'subkey3'=>'subvalue3', 'subkey4'=>'subvalue4' ), 'lastkey'=>'lastvalue' ); DumpArray($array1); //*************************** function DumpArray($ar) { foreach($ar as $k=>$v) { if (is_array($v)) { echo "Array $k - "; DumpArray($v); } else echo "$k - $v<br>"; } echo "End array<br>"; return; } exit(); You can add code to make the presentation neater if you want but at least this shows you how to process the nested arrays.
-
object of class mysqli_result could not be converted to string
ginerjm replied to mattchamp97's topic in PHP Coding Help
Do you have error checking turned on? You have a hanging ) on one of your query statements. If you checked the query results you would have picked it up I think -
So - Not PHP?
-
OR you don't have any query results to loop thru. Here's a cleaned up version of your current code. <?php if(isset($_GET['update'])) { $the_mentor_id = $_GET['update']; $query = "SELECT mentor_id, field2, field3, field4,..... FROM mentor WHERE mentor_id = '$the_mentor_id' "; $qresults = mysqli_query($db, $query); while ($row = mysqli_fetch_assoc($qresults)) { $mentor_id = $row['mentor_id']; echo "<h1>i am h1</h1>"; } } include 'includes/footer.php'; Question - Does the "footer.php" actually contain php code or is it the footer of your html page? Don't name it .php if it is just html code You need to start using prepared queries. Check out the manual. And if you are really new, read the PDO stuff instead of the MySQLI stuff. It's easier and better for you.
-
For future note - please don't post your code in such an unreadable format. Do you work on it in that format??
-
Questions about a Function inside a While loop...
ginerjm replied to Jim R's topic in PHP Coding Help
YOu have to make your functions flexible enough so that you don't have to tinker with them - just alter the arguments coming in. -
Questions about a Function inside a While loop...
ginerjm replied to Jim R's topic in PHP Coding Help
One last thing. Your topic heading say "inside a while loop". I do hope you know enough to not place the actual function inside the while loop. You will be "calling" it From the while loop, but you don't want it written there. IMHO functions are to be placed outside of the main line of your php code. Burying them inside the logic just interrupts one's view of the code when trying to read thru it. Your's is a one line function but when you actually have need to write a real one with many lines you'll see that you don't want to place it in the way of your thought process. Using a function is one of the best reasons to clean up your main logic and get some lines of code out of sight. -
Questions about a Function inside a While loop...
ginerjm replied to Jim R's topic in PHP Coding Help
You mean "learning bumps". -
Questions about a Function inside a While loop...
ginerjm replied to Jim R's topic in PHP Coding Help
You don't code much, do you? The function is as I wrote it. When you want to use it you do: player_name($curr_fname, $curr_lname); The values in these 2 vars will be passed into the function and be referenced as $fn and $ln -
Questions about a Function inside a While loop...
ginerjm replied to Jim R's topic in PHP Coding Help
Maybe I don't understand but I don't see why not. Use unique var names inside the function and pass in values for them via the headers. function player_name ($fn, $ln) { echo '<div><a href="/tag/'. strtolower($fn) . '-' . strtolower($ln) .'">'. $fn . ' ' . $ln .'</a>, '; return; } You are missing the end div tag - is that intentionally? Perhaps you don't even want to start the div in the function? -
So - these people have the power/permission to add these built pages to your site? Is that why you won't know if they exist or not. $pageno = (some source - perhaps the current url); if (is_file( $path . "/$pageno". "html")) { header("Location: $path . $pageno . '.html'); exit(); } This all depends on the source of the page number and what location the pages are all stored in. Basically this is what I would do once my script figures those things out. Of course you have to decide how to handle the non-existent file condition.
-
object of class mysqli_result could not be converted to string
ginerjm replied to mattchamp97's topic in PHP Coding Help
Working with just the code that you seemed to have difficuly with: if($insertresult) { $response = array(); $code = "module_created"; $message = "Your new module was created successfully."; // Get a module id $q = "select moduleID from module_details WHERE moduleName = '$moduleName' AND lecturerID = '$lecturerID'"; if (!$sqlmodID = mysqli_query($con, $q)) { echo "Module Id could not be researched"; exit(); } // Get id from query results $row = mysqli_fetch_assoc($con, $sqlmodID); $modid = $row['moduleID']; // query for students taking this course $sqlstudent = "select idNum from user_info WHERE courseCode = '$courseCode'"; $result = mysqli_query($con, $sqlstudent); // Q. Are you seeking all students or is there only one? // IF more than one you should have a loop here instead of a fetch $row = mysqli_fetch_assoc($con, $result); $q = "insert into student_classlist VALUES ('$modid', '" . $row['idNum'] . "'"; if (!mysqli_query($con, $q)) { $echo "Could not insert new record in classlist for $modid - " . $row['idNum']; exit(); } ... ... ... Note - do error checking when you write code Also I highly suggest that you not adopt JS naming conventions when using php. It will bite you in the A.. eventually for no good reason. Vars can be all lowercase so that you don't have to search all over for where you misplaced a capital letter later on. Your student query seems to be looking for multiple people yet your code really treated it as if it was one row when you did the lone fetch prior to the if statement. As that seemed to be the focus I dropped your if loop. If you are looking for multiple students I suggest a loop using the fetch something like: while ($row = mysqli_fetch_assoc($result) { process one row } -
object of class mysqli_result could not be converted to string
ginerjm replied to mattchamp97's topic in PHP Coding Help
If you read the manual you would see that the result of any query is a resource, not an array. You need to do a fetch or some other operation to extract any values from this query result resource. As for the array map that simply processes an array and produces an array result. Read the manual again. The manual is your friend. Very interesting reading for a noob. If you want to post this block of code we can see the (slightly) bigger picture and add some lines perhaps. -
object of class mysqli_result could not be converted to string
ginerjm replied to mattchamp97's topic in PHP Coding Help
That makes sense but not for that error message. YOu are in a loop with an index but you are not USING the index. How about $studentarray[$i] ? AND - You are referencing the result of your first query which is an array as well. How about doing a fetch on it to get the actual value you want to use? -
object of class mysqli_result could not be converted to string
ginerjm replied to mattchamp97's topic in PHP Coding Help
The If line is #54? Not possible. There is no ref to a mysqli object in that line. -
Read up on the is_file function. Should be just what you need.
-
object of class mysqli_result could not be converted to string
ginerjm replied to mattchamp97's topic in PHP Coding Help
Do we have a line number that points to the one causing the error? -
Sending to mySQL database, but nothing received
ginerjm replied to samanj's topic in PHP Coding Help
It means you either didn't do it or did it wrong. The access and permissions for your data base are incorrect. -
How to extract a given number of characters from a php variable
ginerjm replied to larry29936's topic in PHP Coding Help
Very well done. Now a bit of learning. You don't need to declare $files as an array since the result of the glob call IS an array! -
How to extract a given number of characters from a php variable
ginerjm replied to larry29936's topic in PHP Coding Help
Is that all in one string? As in a variable? Read up on str_replace perhaps? -
Assuming that line 107 is where you try and format your input field, what does that input field actually contain? I do believe that is the problem. You can improve this code by trying to convert POST value to a true date type value before trying to format it. RTFM under "strtotime". Here's something to play with: $input1 = '12/01/20'; if ($dt1 = strtotime($input1)) { $result1 = date('Y/m/d',$dt1); echo "Result 1 is: $input1 becomes $result1<br><br>"; } else echo "Invalid date value 1: $input1<br>"; // A slightly valid input $input2 = 'x01/03/20'; if ($dt2 = strtotime($input2)) { $result2 = date('Y/m/d',$dt2); echo "Result 2 is: $input2 becomes $result2<br><br>"; } else echo "Invalid date value 2: $input2<br>"; // A bad input $input3 = '99abc'; if ($dt3 = strtotime($input3)) { $result3 = date('Y/m/d',$dt3); echo "Result 3 is: $input3 becomes $result3<br><br>"; } else echo "Invalid date value 3: $input3<br>"; exit();
-
Converting and Calculating Numbers (decimal & rounding)
ginerjm replied to martinspire's topic in PHP Coding Help
But NotSunFighter has already solved the math for us.