[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Is my PHP optimum?

Asked by narmi2 in PHP Scripting Language, PHP and Databases

Tags: PHP

Dear Experts,

Is this the best way for me to generate a query which I will later execute to insert the data into the databases?

<?php
      $connection = mysql_connect('server', 'user', 'pass') or die (mysql_error());
      $db = mysql_select_db('database', $connection) or die (mysql_error());
      
      $query  = "Select DataID + 1 as NextID From tblData where DataID < 18581088 Order By DataID desc limit 1";
      $result = mysql_query($query) or die('Error, query `' . $query . '` failed');
      
      $row = mysql_fetch_array($result);
      extract($row);
      
      $the_heading = "the heading goes here";
      $the_date = "2008-06-26 00:00:00"';
      $the_content = "the content goes here";
      $the_categories = "4380138181,43830184182,43801558183,4380158184,43806518185,438418186";

      $generate_query = "insert into tblData ( Heading, Date, Contents, DataID ) values ( '$the_heading', '$the_date', '$the_content', $NextID );";
      
      $categories = explode(",",the_categories);
      
      for ($i=0;$i<count($categories);$i++){
            
            $query  = "select GroupName from tblIDLookup where DataID = $categories[$i]";
            $result = mysql_query($query) or die('Error, query `' . $query . '` failed');
            
            $row = mysql_fetch_array($result);
            extract($row);
            
            $generate_query .= "<br />insert into tblCat (DataID, CatID, CatName) values ($NextID, $categories[$i], $GroupName);";
      }
      
      echo $generate_query;
      
      mysql_close($connection);
?>

It does the following

1. Get the next id but ignore the higher number ids
2. The 4 variables $the_heading, $the_date, $the_content, $the_categories will be textboxes on the users screen which will be filled in by the user
3. I loop through the categories to get the category name from another table based on the exploded category ids, then generate the next query, this continues until all categores are found

I feel this is not very optimum and not using best practices.  Any suggestions for improvements?

When I say "improve" or "optimum", I mean is my code good practice, is it easy on the server, is it fast for the user to download etc etc.

Thanks.
[+][-]07/11/08 08:32 AM, ID: 21983287Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: PHP Scripting Language, PHP and Databases
Tags: PHP
Sign Up Now!
Solution Provided By: abrusko
Participating Experts: 2
Solution Grade: A
 
[+][-]07/11/08 09:32 AM, ID: 21983826Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/16/08 10:01 PM, ID: 22973569Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]11/22/08 06:26 AM, ID: 23020837Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 / EE_QW_2_20070628