Jump to content

The Little Guy

Members
  • Posts

    6,675
  • Joined

  • Last visited

Posts posted by The Little Guy

  1. I looking for your opinion on this:

     

    I am trying to decide if it is a better idea to do one query using many joins or many queries a few joins, which way do you feel is easier to manage and/or faster to do?

     

    I have been told that sometimes it is faster to do multiple small queries than it would be to do one larger join. What is your opinion on this?

     

    here is an example that made me think of this, the first query returns everything needed, but it also returns a little extra which then requires extra php logic to format on the page. This particular query returns the game developers and publishers, so if there is 1 developer and 2 publishers, you will get 2 different publishers and 2 of the same developers.

     

    select d.developer, d.developer_id, p.publisher, p.publisher_id, g.game_id from game_info gi
    left join games g using(game_id)
    left join game_publishers gp on(g.game_id = gp.game_id)
    left join game_developers gd on(g.game_id = gd.game_id)
    left join publishers p on(gp.publisher_id = p.publisher_id)
    left join developers d on(gd.developer_id = d.developer_id) where gi.game_id = 1007

     

    Each one of these queries returns exactly what is needed, so now all you need to do is loop through each result set.

     

    select d.developer, d.developer_id from game_developers gd left join developers d using(developer_id) where gd.game_id = 1007

    select p.publisher, p.publisher_id from game_publishers gp left join publishers p using(publisher_id) where gp.game_id = 1007

     

    So, if you forgot the main question, what do you feel is a better method, many small queries or one large query (especially when using 1 to many and 1 to 1 in the same query)?

  2. I currently have a varchar for my timestamp, I haven't changed it to a timestamp field because I wasn't sure if it would mess up my dates, the dates are in a perfect timestamp format though.

     

    So, if I update the datatype of that field will I get an error, or worse, and invalid date?

  3. This will add two markers to the map

     

    <script type="text/javascript"> 
    function initialize() {
    	var myLatlng = new google.maps.LatLng(38.891033, -96.591797);
    	var myOptions = {
    		zoom: 3,
    		center: myLatlng,
    		mapTypeId: google.maps.MapTypeId.ROADMAP
    	}
    	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    	var myLatlng, marker;
    	myLatlng = new google.maps.LatLng("44.6307","-93.3034");
    		marker = new google.maps.Marker({
    		  position: myLatlng,
    		  map: map,
    		  title:"24.197.217.40"
    	  });
    	  myLatlng = new google.maps.LatLng("44.8205","-92.9256");
    		marker = new google.maps.Marker({
    		  position: myLatlng,
    		  map: map,
    		  title:"174.155.1.75"
    	  });
    }
    
    function loadScript() {
    	var script = document.createElement("script");
    	script.type = "text/javascript";
    	script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
    	document.body.appendChild(script);
    }
    </script> 
    <div id="map_canvas" style="width: 500px; height: 300px"></div> 
    <script>loadScript();</script>

  4. That doesn't really make sense.... but Ill try my best.

     

    $array = array(
    "array1" => array(),
    "array2" => array(),
    "array3" => array()
    );
    
    $is_array = is_array($array['array1']);
    if($is_array)
    echo "this array exists!";
    else
    echo "this array does not exist ";
    
    

  5. You would make your form kinda like this:

     

    <form action="/process/processFiles.php" method="post">
    <table>
    <tr>
    	<td>Filename</td>
    	<td>Archive</td>
    	<td>Delete</td>
    </tr>
    <?php
    foreach(glob('../edit/news/news/*') as $file){
    	echo "<tr>";
    	echo "<td>$file</td>";
    	echo "<td><input type='checkbox' name='archive[]' value='$file' /> $file</td>";
    	echo "<td><input type='checkbox' name='delete[]' value='$file' /> $file</td>";
    	echo "</tr>";
    }
    ?>
    </table>
    </form>

  6. Using PFMaBiSmAd's code, I added some error checking:

     

    <?php
    // your authentication/log in check code would go here...
    
    if(isset($_POST['submit'])){
    if(isset($_POST['delete']) && is_array($_POST['delete'])){
    	foreach($_POST['delete'] as $value){
    		if(file_exists($value)){
    			echo "Delete $value<br />";
    			unlink($value);
    		}else{
    			echo "File Not Found $value; Did Not Delet<br />e";
    		}
    	}
    }
    if(isset($_POST['archive']) && is_array($_POST['archive'])){
    	foreach($_POST['archive'] as $value){
    		if(file_exists($value)){
    			echo "Archive $value<br />";
    			rename($value, "../archives/$filename");
    		}else{
    			echo "File Not Found $value; Did Not Move<br />";	
    		}
    	}
    }
    }
    ?>

  7. I didn't code everything, so here is an example:

     

    This is the page that has the main form of the files you want to move:

    <?php
    foreach(glob('../edit/news/news/*') as $file){
    echo "<input type='checkbox' name='file[]' value='$file' /> $file<br />";
    }
    ?>

     

    This is the page that processes the files once you submit the form:

    <?php
    foreach($_POST['file'] as $file){
    if(is_file($file)){
    	$filename = basename($file);
    	rename($file, "../archives/$filename");
    }
    }
    ?>

     

    Note: I didn't test this.

  8. but....

     

    When called' date=' set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.[/quote']
  9. why do you have imageurl and imagepath? you can build those two based off the other data you have. Second the date field should be "datetime" not an int. it would be formatted like:

    2011-12-12 13:12:20

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.