Jump to content

Warz

Members
  • Posts

    31
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Warz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yes, I guess you're right about that, so far what I worked out is this formula, but to be honest I'm not that great with math, and there seems to be a lot of issues and it's only half working: /** * This function returns the new "index" value to be used based on the new "per page" value */ function calculatevalue($index,$total_rows,$per_page,$old_per_page) { if ($index > $total_rows) { return 0; } return ceil(($index+$old_per_page)/$total_rows)*$per_page; }
  2. Thanks, but I already got a working pagination class.. I just need this specific case to work function calculatevalue($index,$total_rows,$per_page) { if ($per_page > $index) { return 0; } else { // Need code here to solve issue... return $index; } }
  3. Hi, I'm working on a pagination for my site and I'm having some trouble finding a function. To explain the function, you need to know that user can choose to display "any amount of rows per page" I'm using an index to determine which page user are on. For instance if rows per page is 2 and index is 0 then I'm on page 1. Basically here is two examples: Per page: 2 IndexPage 01 22 43 64 Per page: 5 IndexPage 01 52 103 154 Ok, so here's the thing: say if index is 14 and per page is 2 and then I change to per page 10, well then we can't use 14 as index anymore, since valid index is only 0,10,20,30 and so on... I would need to make 14 --> 10 Now, I'm not sure what is the best way to calculate this....or what functions to use?
  4. Hi, you need to create the viewstock.php page yourself... After any php file you can add ?anything=variable - this is simply to send variables to another page. You can add many variables by using &... example: ?name=john&age=20&userid=28294 then you can get these variables on the page you visit. Say you link to viewstock.php?name=john&age=20&userid=28294 then you can create viewstock.php and get these variables like this: <?php $username = $_GET['name']; $userage = $_GET['age']; $userid = $_GET['userid']; ?> Now you can also use these variables to make a new SQL query and get stock info (viewstock.php?id=10242): <?php $stockid = $_GET['id']; $sql = "select * from stocks WHERE id = ".mysql_real_escape_string($stockid).""; $res = mysql_query($sql); .... ?>
  5. for ($i=0; $i < $num_results; $i++) { $row = mysql_fetch_assoc ($result); echo '<tr><td>'; echo '<p><strong>'.($i+1).'.</td><td>'; echo htmlspecialchars(stripslashes($row['title'])); echo "</strong></td><td>"; echo '<a href="viewstock.php?id='.stripslashes($row['cxcode']).'">View</a>'; echo '</td><td>'; echo stripslashes($row['reldate']); echo '</td><td>'; echo stripslashes($row['strtdate']); echo '</td><td>'; echo stripslashes($row['enddate']); echo '</td><td>'; echo '<form action="stckprofile.php"><input type="submit" value="View" name="stckview"></form>'; echo '</td><td>'; echo '<form action=""><input type="submit" value="Delete" name="stckdel"></form>'; echo '</td>'; Then on viewstock.php you just need to get the variable like this: $cxcode = $_GET['id'];
  6. When you echo out the stocks also echo out and "id" or something that can identify each stock. I do like this: echo '<a href="viewstock.php?id='.$row['id'].'">View</a>';
  7. Yes you have, I thought you ment textfield... you mean checkbuttons right? Then it's a lot more simple... <?php $arr=$_POST['text']; // implode: $list = implode(",", $arr); ?>
  8. You could make arrays in your form like this: <input type="text" name="text[1]" /> <input type="text" name="text[2]" /> <input type="text" name="text[3]" /> <input type="text" name="text[4]" /> ...and do like this: <?php $arr=$_POST['text']; $i=0; foreach ($arr as $key => $value) { if ($value != "") { $variables[$i] = $value; } $i++; } // implode: $list = implode(",", $variables); ?>
  9. Yes, they both have values, however global $a; doesn't seem to get any values.... when I go "echo $a;" inside the function it echos out nothing, however outside the function it works... so the problem has to do with the fact that "global" some how doesn't work. Well register globals are off. I'm not sure which setting would magically populate my variables tbh. And one more thing, this might not be a server issue after all. I just tried creating a 100% blank php file and filled it with this script and it worked... So then obviously it must be something that my current script is causing... I havn't made that script myself and it's pretty huge. To make sure there isn't any conflicts between variables I named them something completely random like "hadwawiodhawo" and "hadoakwdjowjwo" and still didn't work. Now it must be said that I'm including this code that doesn't work correctly on a template page, maybe there are some issues here. I might just have to do it the hard way but not using globals :'(
  10. Your not doing anything wrong, the code works fine for me, just tried it. Maybe you can post more of the code? for me the code echos this: <div id="results"><p><strong>1.Title: which should be right...
  11. Solution 1. <?php echo '<a href="xxxx.php">Text</a>'; ?> Solution 2. <?php echo "<a href=\"xxxx.php\">Text</a>"; ?> Solution 3. <?php print ('<a href="xxxx.php">Text</a>'); ?> ... more ways too I prefer number 1.
  12. If I understand you correctly this is what you need to do in <form> you choose action="" this will send request to same page... then you can either include the upload.php script on your page or simply copy the code over. Then check if user has submitted. Assuming post value look like this <input type="submit" name="submit" value="Upload"> Example: if (isset($_POST['submit'])) // Has user submitted/uploaded yet? { include 'upload.php'; // If so, let's include this page } else // if not.... { Place your original page here... the one user will see before (and after) uploading. }
  13. That's just an example code I tested on both servers... my real code is different obviously and has a lot more lines, however I tried this exact code on both servers, and it's just different behaviour/result.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.