PHP Problem. only page id links

disturbedart

Member
Messages
474
Reaction score
1
Points
18
Hello i have had a dumb moment and cant think how to do this, i have been creating a CMS at the moment and i want to be able to have pages with index.php?pid=xxx but also be able to list standard links so links to a different directory.

Does anyone got any ideas? as my current method only allows index.php?pid=xxx links

I was thinking an IF statement but cant think of how to code this in at the moment.

Possible create a new field in the database called "ext" and if this is set to 1 then it shows a directory link if set to "0" then it displays index.php?pid=xxx link. And i would set up a check box on the create/edit pages section to set this.

Any thoughts?

Thanks.

PHP:
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Build Main Navigation menu and gather page data here -----------------------------------------------------------------------------
$sqlCommand = "SELECT id, linklabel FROM pages WHERE showing='1' ORDER BY id ASC"; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection)); 
$menuDisplay = '<ul>';
while ($row = mysqli_fetch_array($query)) { 
    $pid = $row["id"];
    $linklabel = $row["linklabel"];
 
 $menuDisplay .= '<li><a href="index.php?pid=' . $pid . '">' . $linklabel . '</a></li>';
 
} 
$menuDisplay .= '</ul>';
mysqli_free_result($query); 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
//mysqli_close($myConnection);
 

John Rambo

New Member
Messages
27
Reaction score
0
Points
1
Add a new filed in table, for example url:
PHP:
while ($row = mysqli_fetch_array($query)) { 
  $linklabel = $row["linklabel"];
  if ( $row['url'] ) { // && you can check $row['ext'] as well
    $menuDisplay .= '<li><a href="' . $row['url'] . '">' . $linklabel . '</a></li>';
  } else {
    $pid = $row["id"];
    $menuDisplay .= '<li><a href="index.php?pid=' . $pid . '">' . $linklabel . '</a></li>';
  }
}
You can add 2 fileds, and show url if only ext field is set to 1.
 

disturbedart

Member
Messages
474
Reaction score
1
Points
18
Thanks this worked perfectly i dont know why i didnt think of this method,
Cheers,
Kyle.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
PHP:
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection));

Don't use die when outputting HTML. You'll get invalid HTML.

Outputting database error messages to non-admin users discloses too much information. Instead, log the MySQL error message. For some errors (such as those related to missing or invalid values), output your own error message to the user and what action the user can take to address it. For the rest, inform the user that there was an internal error.
 
Top