Jump to content

jtified

Member
  • Posts

    16
  • Joined

  • Last visited

jtified's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. jtified

    About pagination

    It worked...thanks a millionnnnnnnnnnnnn!! btw: whats the difference on using mysql_fetch_row bet mysql_num_rows?
  2. jtified

    About pagination

    Hi guys! I've created a paginator and it seems like I'm getting infinite page numbers..In my sample code, I have the database "experiment" , table "specimen01" , 3 columns and 12 rows each labels has its own value, I just didn't bother to fill it up. TABLE specimen01 ================ | id | fname | lname | ================ | 1 | | | | | | | | | | | | | | | v | 12 =============== This is my code: //CONNECT TO SERVER AND DB $mysqlConnect = mysql_connect ('localhost','root',''); if (!$mysqlConnect) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully to server' . ' '; $mysqlDbConnect = mysql_select_db('experiment'); if (!$mysqlDbConnect) { die('Could not connect to database: ' . mysql_error()); } echo 'Connected successfully to database' . ' '; //COUNT NUMBER OR ROWS $query = 'SELECT * FROM specimen01'; $result = mysql_query($query); $r = mysql_fetch_row($result); $numrows = $r[0]; $rowsperpage = 3; $totalpages = ceil($numrows / $rowsperpage); if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { $currentpage = $_GET['currentpage']; } else { $currentpage = 1; } if ($currentpage > $totalpages) { $currentpage = $totalpages; } if ($currentpage < 1) { $currentpage = 1; } $offset = ($currentpage - 1) * $rowsperpage; $query = "SELECT * FROM specimen01 LIMIT $offset, $rowsperpage"; $result = mysql_query($query); $mytable =""; while ($list = mysql_fetch_assoc($result)) { $mytable = $mytable . " {$list['lname']} {$list['fname']} "; } //BUTTONS $range = 3; for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [$x] "; } else { echo " $x "; } } } if ($currentpage > 1) { echo " FIRST "; $prevpage = $currentpage - 1; echo " Back "; } if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; echo " Next "; echo " LAST "; } mysql_close($mysqlConnect); ?> I'm getting 334003 pages. I only need to have 3 data per page. so it needs to have 4 pages only since I do have 12 data in my table. This is kinda confusing to me since I'm a beginner, I only made this sample database that's why has few data. You might ask why separate this few data. This is just my experiment, I'm actually working on different database that needs to have a limit per page. Hope someone can help me out on this...Cheers!
  3. Well, I was also thinking the same way..but I wasn't so sure if there will be a time that I need to insert an item in the beg/end of an array..LOL..and now you've said it, I got the point now..thanks a lot..great help! Have a good day. :cool:
  4. So we can insert additional items in an assoc. array in the end of the array but not in the beginning of it.
  5. @dms Tried it..none of it works..thanks anyway.. @falken I see. Guess there's no other way to do it..thanks too..
  6. Hi guys! How can I insert and array with string index or string key. Like for example <?php $example['breakfast'] = 'ham and egg'; $example['lunch'] = 'steak'; $example['snack'] = 'fish and chips'; print_r ($example); ?> this outputs: Array ( [breakfast] => ham and egg [lunch] => steak [snack] => fish and chips ) If I wanted to use array_push() or array_unshift(), HOW can I insert an item in the array "$example" that has a string index or string key of ['dinner']. Something like this: <?php $example['breakfast'] = 'ham and egg'; $example['lunch'] = 'steak'; $example['snack'] = 'fish and chips'; array_push($example['dinner'] = 'pizza'); print_r ($example); ?> It generates the output : Warning: array_push() expects at least 2 parameters, 1 given in C:\wamp\www\SMS 2.0\sample.php on line 16 Array ( [breakfast] => ham and egg [lunch] => steak [snack] => fish and chips [dinner] => pizza ) But you see the dinner was inserted..but how do I remove the error.
  7. Can you tell me what is the REAL difference of FOR LOOP and WHILE LOOP? I know both of them has to be executed until the condition is false..same thing when you're saying "It will run a specified number of times". Ive been looking around for answers over the internet but people keeps on saying that : while loop - used for looping until a condition is satisfied and when it is unsure how many times the code should be in loop <------ HUH? even in FOR LOOPS it will run until a condition is satisfied or results to false. And in FOR LOOPS you're not also sure how many times it will run, that is if you didn't use a number. for loop - used for looping until a condition is satisfied but it is used when you know how many times the code needs to be in loop. I hope someone can give me a clear and precise answer. Thanks!
  8. [/color] var a =10; var b = 20; result = (a && ; document.write(result);
  9. [/color] var patt1=new RegExp("e","g"); do { result=patt1.exec("The best things in life are free"); document.write(result); } while (result!=null)
  10. [/color] var str = "For more information, see Chapter 3.4.5.1"; var re = /(chapter \d+(\.\d)*)/i; <----------------- var found = str.match( re ); document.write(found );
  11. I understand now. Thank you for that!
  12. Hi there! I'm a beginner when it comes to programming thats why I want to know what ARE the differences of declaring a variable like this: function function_name(var1,var2,...,varX) { some code } TO this: function function_name() { var1; var2; varX; etc....... some code }
  13. So there's no good fix using CSS here..*sigh*. Thanks a lot though.
×
×
  • Create New...