From 7eb055141bae63b85cef93e5d6f67e3016219d7b Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 13 Dec 2008 10:01:56 -0500 Subject: Optimized posting Previously, Four Island posted a blog, and then searched through the table looking for it so it could retrieve its ID. Now, the "mysql_insert_id()" function is used instead. --- pages/admin.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'pages') diff --git a/pages/admin.php b/pages/admin.php index b21948c..aff21cf 100755 --- a/pages/admin.php +++ b/pages/admin.php @@ -44,24 +44,21 @@ if (isLoggedIn()) $insdraft = "INSERT INTO drafts (title,author,text,slug) VALUES (\"" . addslashes($_POST['title']) . "\",\"" . sess_get('uname') . "\",\"" . addslashes($_POST['text']) . "\",\"" . generateSlug($_POST['title'],'updates') . "\")"; $insdraft2 = mysql_query($insdraft); - $getdraft = "SELECT * FROM drafts ORDER BY id DESC LIMIT 0,1"; - $getdraft2 = mysql_query($getdraft); - $getdraft3 = mysql_fetch_array($getdraft2); - - addTags($getdraft3['id'], $tags, 'draft'); + $id = mysql_insert_id(); + addTags($id, $tags, 'draft'); $template = new FITemplate('admin/draftSuccess'); - $template->add('ID', $getdraft3['id']); + $template->add('ID', $id); } else if ($_POST['type'] == 'instant') { - postBlogPost($_POST['title'], sess_get('uname'), $tags, $_POST['text']); + $id = postBlogPost($_POST['title'], sess_get('uname'), $tags, $_POST['text']); - $getpost = "SELECT * FROM updates ORDER BY id DESC LIMIT 0,1"; + $getpost = "SELECT * FROM updates WHERE id = " . $id; $getpost2 = mysql_query($getpost); $getpost3 = mysql_fetch_array($getpost2); $template = new FITemplate('admin/postSuccess'); - $template->add('ID', $getpost3['id']); + $template->add('ID', $id); $template->add('CODED', $getpost3['slug']); } else { if ($_POST['type'] == 'normal') @@ -143,17 +140,17 @@ if (isLoggedIn()) $template->add('ID', $_GET['id']); } else if ($_POST['type'] == 'instant') { - postBlogPost($_POST['title'], sess_get('uname'), $tags, $_POST['text']); + $id = postBlogPost($_POST['title'], sess_get('uname'), $tags, $_POST['text']); $deldraft = "DELETE FROM drafts WHERE id = " . $_GET['id']; $deldraft2 = mysql_query($deldraft); - $getpost = "SELECT * FROM updates ORDER BY id DESC LIMIT 0,1"; + $getpost = "SELECT * FROM updates WHERE id = " . $id; $getpost2 = mysql_query($getpost); $getpost3 = mysql_fetch_array($getpost2); $template = new FITemplate('admin/postSuccess'); - $template->add('ID', $getpost3['id']); + $template->add('ID', $id); $template->add('CODED', $getpost3['slug']); } else { if ($_POST['type'] == 'normal') -- cgit 1.4.1