Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL PHP CMS URL creation(need to edit)
    text
    copied!<p>I apologize for the length of this question, and would like to say thanks in advance.</p> <p>Below is the snippet of code in question. I have a MySQL table that stores information from a custom built PHP MySQL CMS program based off of this tutorial:<a href="http://fwebde.com/web-design/creating-a-php-cms-part-1/" rel="nofollow">cms tutorial</a>. As you can see in the List Pages and the Display Admin functions, the URL is built with the base url and the ID as well as the title. The ID is the primary key in the MySQL table that pulls all of the necessary information to be displayed on the page. How would I rewrite the code below so that it displays the title only in the URL and not the ID, but still go off of the ID as the unique identifier for displaying information in the pages?</p> <p>From functions.php:</p> <pre><code>'// Display center bottom column function centerbottomcolumn() { if ($_GET['id']) { $pageID = (int) $_GET['id']; $result = mysql_query("SELECT centerbottomcolumn FROM pages WHERE id='$pageID'"); $row = mysql_fetch_array($result); echo $row['centerbottomcolumn']; } else { $result = mysql_query("SELECT value FROM settings WHERE name='homePage'"); $row = mysql_fetch_array($result); $pageID = $row['value']; $result = mysql_query("SELECT centerbottomcolumn FROM pages WHERE title='$pageID'"); $row = mysql_fetch_array($result); echo $row['centerbottomcolumn']; } </code></pre> <p>}</p> <pre><code>// List the pages function listPages() { // List the home page first $result = mysql_query("SELECT value FROM settings WHERE name='homePage'"); $row = mysql_fetch_array($result); $homeID = $row['value']; $result = mysql_query("SELECT title FROM pages WHERE id='$homeID'"); $row = mysql_fetch_array($result); $homeTitle = $row['title']; echo "&lt;li&gt;&lt;a href='" . BASE_URL . "/index.php'&gt;$homeTitle&lt;/a&gt;&lt;/li&gt;"; // List the rest of the pages $result = mysql_query("SELECT id, title FROM pages"); while ($row = mysql_fetch_array($result)) { // Do not list the home page twice if ($row['title'] != $homeID) { $pageID = $row['title']; $pageTitle = $row['title']; echo "&lt;li&gt;&lt;a href='" . BASE_URL . "/?id=$id&amp;title=$pageTitle'&gt;$pageTitle&lt;/a&gt;&lt;/li&gt;"; } } </code></pre> <p>}</p> <pre><code>// Display admin table function displayAdmin() { // Find the home page ID $result = mysql_query("SELECT value FROM settings WHERE name='homePage'"); $row = mysql_fetch_array($result); $homeID = $row['value']; // Display a table $result = mysql_query("SELECT id, title, date FROM pages"); echo '&lt;table width="961"&gt;'; echo '&lt;tr height="50"&gt; &lt;th align="left"&gt;ID&lt;/th&gt; &lt;th align="left"&gt;Title of the Page&lt;/th&gt; &lt;th align="left"&gt;Date Created&lt;/th&gt; &lt;th align="left"&gt;Actions&lt;/th&gt; &lt;/tr&gt;'; while ($row = mysql_fetch_array($result)) { $id = $row['id']; $title = $row['title']; $date = date('M d, Y', $row['date']); echo "&lt;tr&gt; &lt;td&gt;$id&lt;/td&gt; &lt;td&gt;&lt;a href='". BASE_URL . "/id=$id&amp;title=$title'&gt;$title&lt;/a&gt;"; if ($id == $homeID) { echo ' &lt;strong&gt;(Home Page)&lt;/strong&gt;'; } echo "&lt;/td&gt; &lt;td&gt;$date&lt;/td&gt; &lt;td&gt;&lt;a href='edit.php?id=$id'&gt;Edit&lt;/a&gt;&lt;/td&gt;&lt;td&gt; &lt;a href='confirm.php?id=$id'&gt;Delete&lt;/a&gt;&lt;/td&gt;&lt;td&gt; &lt;a href='sethome.php?id=$id'&gt;Set as Home&lt;/a&gt;"; } echo '&lt;/table&gt;'; </code></pre> <p>}</p> <pre><code>// Get array with page IDs function getArray() { $result = mysql_query("SELECT id FROM pages"); $IDs = array(); $i = 0; while ($row = mysql_fetch_array($result)) { $IDs[$i] = $row['id']; $i++; } return $IDs; </code></pre> <p>}</p> <pre><code>From index.php: (above head tag) require_once 'functions.php'; connect(); $IDs = getArray(); (from body) &lt;?php if (in_array($_GET['id'], $IDs) || !$_GET): ?&gt; &lt;?php centerbottomcolumn(); ?&gt; &lt;?php else: ?&gt; &lt;!-- Show a not found error --&gt; &lt;p&gt;Not found&lt;/p&gt; &lt;?php endif; ?&gt;' </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload