PHP Get Data on based &read={id}

Status
Not open for further replies.

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
sup yo
I'm trying to get data from database based on index.php?url=hk&staffapps&read={id}. {id} is based on data that is from database. hoping this makes sense.

So my code:
PHP:
        <table align = "center">
          <tr>
            <th>ID</th>
            <th >Username</th>
            <th>Age</th>
            <th >Skype</th>
            <th >Read</th>
          </tr>
        <?php
            $q = mysql_query("SELECT * FROM staffapps");
                while ($m = mysql_fetch_array($q)) {
           
            ?>
          <tr align = "center">
            <td ><?php echo $m['id']; ?></td>
            <td ><?php echo $m['un']; ?></td>
            <td ><?php echo $m['age']; ?></td>
            <td ><?php echo $m['skype']; ?></td>
            <td><a href="http:/mydomain.com/index.php?url=hk<?php echo $m['id'];?>">Read </a></td>
          </tr>
       
      </table>
                <?php }
                 
          if(isset($_GET['read'])){
          $g = $_GET['read'];
          $sql = mysql_query("SELECT * FROM staffapps WHERE id = '$g'");
          while($r = mysql_fetch_array($sql){
             
        echo'
          <table align="cetner">
          <tr>
          <th> ID </td>
          <th>Username</td>
          <th>Real Name</th>
          <th>Age</th>
          <th>Skype</th>
          <th>Position</th>
          <th>Online Hours</th>
          <th>Experiences</th>
          <th>Why</th>
          <th>Difference</th>
          </tr>
          <tr>
          <td> '. $r['id'] .'</td>
          <td>  '. $r['un'] .'</td>
          <td>  '.$r['realname'] .'</td>
          <td>'. $r['age'] .'</td>
          <td> '. $r['skype'] .'</td>
          <td>  '/*.if($r['pos'] == "1") { echo "Events Staff"; } else{ echo "Moderator";}. '*/'</td>
          <td> '.$r['hours'].'</td>
          <td>'.$r['exp'].'</td>
          <td>'.$r['why'] .'</td>
          <td>'. $r['diff'].'</td>
          </tr></table>';
          }
         }   else {
              // nothing to do....
          }?>
When i remove the if(isset($_GET['read'])) part page works well but not if it exists. Any help appreciated.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
This may sound stupid, but are you ACTUALLY accessing the page with a &read={id} parameter? I can't see why what you've done wouldn't work.

Can you post the full page code, and the URL you're viewing?

PS: that code is ridiculously unsafe.
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
This may sound stupid, but are you ACTUALLY accessing the page with a &read={id} parameter? I can't see why what you've done wouldn't work.

Can you post the full page code, and the URL you're viewing?

PS: that code is ridiculously unsafe.
The url is like:
index.php?url=hk&staffapps&read= 2 for example. thats full code aswell! Calling this file in a div when its index.php?url=hk&staffapps
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
The url is like:
index.php?url=hk&staffapps&read= 2 for example. thats full code aswell! Calling this file in a div when its index.php?url=hk&staffapps
Are you getting any errors?

I've just noticed you're missing a closing-bracket on one line. Where you've put:
PHP:
while($r = mysql_fetch_array($sql){
Replace with
PHP:
while($r = mysql_fetch_array($sql)){
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
Are you getting any errors?

I've just noticed you're missing a closing-bracket on one line. Where you've put:
PHP:
while($r = mysql_fetch_array($sql){
Replace with
PHP:
while($r = mysql_fetch_array($sql)){
Changed that, now the main page works but not read case. I don't get any errors. Page is like this:
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Changed that, now the main page works but not read case. I don't get any errors. Page is like this:
That looks more like an issue with the rest of your app, not just this page.

I visited the page and viewed the source, it looks like your templating system isn't working.

Code:
<link rel="stylesheet" href="/app/tpl/skins/{skin}/styles/style.css">
<link rel="stylesheet" href="/app/tpl/skins/{skin}/styles/online.css">

It shouldn't be saying {skin}, I'm assuming.
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
That looks more like an issue with the rest of your app, not just this page.

I visited the page and viewed the source, it looks like your templating system isn't working.

Code:
<link rel="stylesheet" href="/app/tpl/skins/{skin}/styles/style.css">
<link rel="stylesheet" href="/app/tpl/skins/{skin}/styles/online.css">

It shouldn't be saying {skin}, I'm assuming.
Other pages do work well, its just when i go to index.php?url=hk&staffapps&read=2 . Maybe i should do another page :S
 

Haid

Member
Dec 20, 2011
363
448
Are you giving it the "&read=" part in in the table?
Code:
<td><a href="http:/mydomain.com/index.php?url=hk<?php echo $m['id'];?>">Read </a></td>

Not sure if it's because you've edited to remove the domain name?
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
Are you giving it the "&read=" part in in the table?
Code:
<td><a href="http:/mydomain.com/index.php?url=hk<?php echo $m['id'];?>">Read </a></td>

Not sure if it's because you've edited to remove the domain name?
I've changed that here, however. It's my domain in original code.
 

Haid

Member
Dec 20, 2011
363
448
I've changed that here, however. It's my domain in original code.
I mean the last part, it is like this isn't it - yourdomain.com/index.php?url=hk&read=<?php echo $m['id'];?>
Your OP just states - yourdomain.com/index.php?url=hk<?php echo $m['id'];?>
 

Haid

Member
Dec 20, 2011
363
448
Nah, for example when i click read for id 2, it redirects me to index.php?url=hk&staffapps&read=2
I feel like this might be an issue with the rewriting and how your cms handles accessing pages. Try turning the row into a form and submit the id to the staffapps page, then get the post data instead.
 

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
PHP:
if($_GET['id']) {
$g = $_GET['id'];
          $sql = mysql_query("SELECT * FROM staffapps WHERE id = '$g'");
          while($r = mysql_fetch_array($sql)){
              
        echo'
          <table align="cetner">
          <tr>
          <th> ID </td>
          <th>Username</td>
          <th>Real Name</th>
          <th>Age</th>
          <th>Skype</th>
          <th>Position</th>
          <th>Online Hours</th>
          <th>Experiences</th>
          <th>Why</th>
          <th>Difference</th>
          </tr>
          <tr>
          <td> '. $r['id'] .'</td>
          <td>  '. $r['un'] .'</td>
          <td>  '.$r['realname'] .'</td>
          <td>'. $r['age'] .'</td>
          <td> '. $r['skype'] .'</td>
          <td>  '.if($r['pos'] == "1") { echo "Events Staff"; } else{ echo "Moderator";}. '</td>
          <td> '.$r['hours'].'</td>
          <td>'.$r['exp'].'</td>
          <td>'.$r['why'] .'</td>
          <td>'. $r['diff'].'</td>
          </tr></table>';
          }}
Is anything wrong in this code? neither the table head isn't showing...
 

Haid

Member
Dec 20, 2011
363
448
Is anything wrong in this code? neither the table head isn't showing...
'/*.if($r['pos'] == "1") { echo "Events Staff"; } else{ echo "Moderator";}. '*/'
Same reason as you commented it out the first time, you can't do an if statement like that (line 26) in the middle of an echo, you'll need to use a ternary operator if you want to do that, otherwise do the if statement before you echo the table data and define $position as a variable, then you can just echo the variable in that <td>
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
Same reason as you commented it out the first time, you can't do an if statement like that (line 26) in the middle of an echo, you'll need to use a ternary operator if you want to do that, otherwise do the if statement before you echo the table data and define $position as a variable, then you can just echo the variable in that <td>
First line requires an isset validator.
Glad I quit PHP lol
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
Fixed this, @Wess shut the fucking thread please. Thanks anyone who contributed.
Can I also suggest just to make it look a little cleaner, add a rule in your web.config:


Code:
<rule name="HouseKeeping Staff Apps">
                <match url="index.php?url=hk/staffApps/([0-9]+)" />
                <action type="Rewrite" url="index.php?url=hk&amp;staffapps&amp;read={R:1}" />
                </rule>

So then your url would be:

index.php/staffApps/2
which would redirect it to this:
index.php?url=hk&staffapps&read=2
 
Status
Not open for further replies.

Users who are viewing this thread

Top