-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
Since the array in the example is sorted it seems to me the answer is 70, not 140. The question was 'between' 2 values, not including the 2 themselves.
-
Hope you learn a lot from our efforts to help you. Good luck!
-
"In My Humble Opinion" and "In My Opinion" Sorry
-
For someone just starting out you chose a difficult task. Learning about how php works and the many functions to use is quite enough. As for learning Mysqli first - IMHO you are better off stopping that and moving to PDO. A much better interface and IMO a much simpler one.
-
I hope you read thru each of our examples and learn from them. You have a long ways to go, so here's a good start. PS - you should learn how to use PDO instead of MysqlI
-
I left out a trailing parentheses
-
So you might need to have several arrays to handle different classes of people's habits? Or a mutli-dimensional array that combines them all. Either way, you would add a second arg to the function that adds this 'class' value.
-
You mean add more code lines?
-
You were showing it as coming from the input from a form. Anywhere you are getting it you can use. I don't know exactly what type of value you are using since you were simply showing something like 0 or 5 in your first post. Since I wrote the array of greetings using a string value as the key, I made sure to convert whatever value you passed into the function to a string too. I dont know how you were getting a time. I'm guessing it was a difference between actual and expected times.
-
So? You write the array and save it as its own file. Then you include it in every script that needs to use it. The really smart thing would be to include the function there too and use an arg to feed it and accept a result when you call the function. function GetGreeting($time) { $greetings = array( '0'=>'Good morning', '5'=>'You are late' '10'=>'you are real late' ); $str = (string) $time; return $greetings[$str]; } In your other scripts you do an "include 'getgreetings.php;'" and then call it with: $greeting = GetGreeting($time); and then output $greeting.
-
I told you how to do it.
-
I think my re-write has taken care of his lackluster logic.
-
Create the greetings array in your function. Something that links the time values (0,5) to the greeting label you want to see. Then pass a single argument to the function - the post time value. Let the function use that value to look up in your new array and return the text you want to output. I'll let you figure this out - good practice.
-
Try this: <?php session_start(); error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); $results_per_page = 10; if (!isset($_POST['sayfa'])) { $page = 1; // find total # of rows $sql = 'SELECT * FROM icerik'; $result = mysqli_query($conn, $sql); $number_of_results = mysqli_num_rows($result); $number_of_pages = ceil($number_of_results / $results_per_page); $this_page_first_result = 1; } elseif(isset($_POST['sayfa']) { $page = $_POST['sayfa']; $number_of_pages = $_POST['number_of_pages']; $number_of_results = $_POST['number_of_results']; $this_page_first_result = (($page - 1) * $results_per_page) + 1; } else { echo "Invalid response from page"; // ERROR NO GET, NO POST exit(); } // get set of rows $q = "select * from icerik order by icerik_id desc limit $results_per_page offset $this_page_first_result"; $sorgu = mysqli_query($conn, $q); //******************************* // Show the page echo 'div id="orta">'; // show set of rows while($goster = mysqli_fetch_assoc($sorgu)) { $fld1 = $goster['baslik']; $fld2 = substr($goster['yazi'], 0, 300); $fld3 = $goster['yazar']; $code=<<<heredocs <div id="konu"> <div id="baslik"> $fld1 </div> <div id="yazi" $fld2 </div> <div id="yazar"> $fld3 </div> </div> heredocs; echo $code; } //******************************* // show the form of page numbers echo '<div id="sayfalama">'; echo "<form method='POST' action='index.php'>"; // change to "type='hidden'" after testing echo "<input type='text' name='number_of_pages' value='$number_of_pages'>"; // change to "type='hidden'" after testing echo "<input type='text' name='number_of_results' value='$number_of_results'>"; echo '<br><br>'; for ($i = 1; $i <= $number_of_pages; $i++) { // show page # choices echo "<input type='submit' name='sayfa' value='$i' size=2>"; echo " "; } echo "</form>"; echo "</div>"; // sayfalama echo "</div>"; // orta exit();
-
Post ALL of your code here. ALL of it. I will copy it from here and see how bad it is. We will start from there. If it is very bad that may help me to help you by knowing what skills you have. One chance. I repeat: ALL OF YOUR CODE. No links. Just code.
-
If you have trouble with English then this forum could be a problem for you. Time to read some books and teach yourself how to write code.
-
This guy just doesn't get it. We've asked for him to post his code several times here and he refused. Now he thinks he can send it to you and have you re-write it for him.
-
Barand - you have much more patience than I.
-
Well, then you have to FIX your code so that you can continue working on the OTHER PROBLEM. Good bye. You are not trying to be a programmer. I am giving you Very Simple instructions and you "do not understand". Can't make it any simpler.
-
That $sql line was a representation of YOUR select line. As I explained later put the echo after that line. And your latest use of my code is showing you that you have 4 items in your $r array: icerik_id baslik yazi yazar So where is this 'name' item? Where are you trying to add it to the $r array? Read your code - debug it. And if this is above you and you don't want to do the work, it's time to get out.
-
That means that whatever items you have in the array $r there are none named 'name'. Do this before the first error line: echo "r is <pre>",print_r($r,true),"</pre>"; and it will show you each and every item in that array. Then you will understand and can begin to search your prior code to see why you don't have a 'name' item. I don't know why I am helping you out here since you refuse to do the other thing I asked.....
-
Help with depreciated 'each' function replacement
ginerjm replied to sks2416's topic in PHP Coding Help
C'mon. Give him a break. He was more concerned about the 'each' question and didn't notice the design. I doubt that the OP has the desire to re-design his database, maybe not even the skills. -
Help with depreciated 'each' function replacement
ginerjm replied to sks2416's topic in PHP Coding Help
It does appear that you have a bad database design in use. Never combine items into a single column of a table. You have 3 columns that are doing that. -
I want you to add that last line (echo) to your script right after the spot where the $sql var is defined and then run your script. You should see the output of that echo on your screen. Copy and past it into a post here. Pretty simple, eh?
-
How about adding echo of the query string so we can all see what you have created? Something like: $sql = "select xxxxx sss xxx "; echo "sql is $sql"; Then cut and paste what comes out on your screen when you run it and put it into your next post.