Jump to content

xtopolis

Members
  • Posts

    1,422
  • Joined

Posts posted by xtopolis

  1. So, there were a few things missing with you code.  Mainly, the while loop didn't have {} braces, and also it was freeing the mysqli result after the first iteration due to that.

     

    Here's your code cleanup and formatted in a way I prefer (I had trouble looking at your formatting, but that's just a personal thing).

    <br />
              <a href='index.php'> Back Home </a>
              <br />
      <br />
    <?php
    // -------------------------- Connect to DB
    include ('connect_script.php');
    // ------------------------------ Color variable for alternating table colors
    $color = 1;
    // ------------------------- Query Parameters
    
    $select = "SELECT (number) AS id, (first_name) AS fn, (last_name) AS ln, (position) AS position FROM table WHERE position = 'X' ";
    
    $get = @mysqli_query ($dbc, $select);
    
    // ------------------------- Run Query
    
    if($get)
    {
    // ------------------------Start table
    
    echo "
    <div style='border-style: solid;'>
    
    <table align='left' border='1'>
    
    <tr>
    <td>People</td>
    </tr>
    
    
    <tr>
    <td>ID</td><td>First Name</td><td>Last Name</td><td>Position</td>
    </tr>";
    
    // ------------------------ Retrieve People
    while ($row = mysqli_fetch_array($get, MYSQLI_ASSOC))
    {
    
    
    	if($color==1)
    	{
    		echo ' <tr bgcolor= #47EA7D>
    				<td>' . $row['id'] . '</td><td>' . $row['fn'] . '</td><td>' . $row['ln'] . '</td><td>' . $row['position'] . '</td>
    				</tr>';
    		$color = '2';
    
    	}else{
    		echo ' <tr bgcolor= #A4C8B0>
    				<td>' . $row['id'] . '</td><td>' . $row['fn'] . '</td><td>' . $row['ln'] . '</td><td>' . $row['position'] . '</td>
    				</tr>	';
    		$color= '1';
    	}
    
    }//end while loop
    // ----------------------- Close table
    
    echo "</div>
    		  </table>";
    
    mysqli_free_result ($get);
    
    
    }//"get" (mysql query) if statement
    
    // --------------------   IF ERROR WITH QUERY
    
    else {
    echo "Didn't connect";
    }
    
    
    
    // ---------------------- Spaces --> This is the code that doesn't appear to affect the space at the bottom of the table
    
    echo "<br />
              <br />
              <br />";
    
    
    ?>

     

    ^^--- will this code work?  I don't know.  If an error exists after you add the while {} braces, then it's with the mysql connection/query.

     

    I made a sample array and it "worked" as far as I could tell what you were trying to do.  I didn't see anything in here about a second table though.  Here's the code I tested with.

    <?php
    error_reporting(E_ALL);
    
    echo "<br />
              <a href='index.php'> Back Home </a>
              <br />
      <br />";
    
    
    
    // -------------------------- Connect to DB
    
    
    //include ('connect_script.php');
    
    
    
    
    
    
    // ------------------------------ Color variable for alternating table colors
    
    $color = 1;
    
    
    
    
    
    
    // ------------------------- Query Parameters
    
    //$select = "SELECT (number) AS id, (first_name) AS fn, (last_name) AS ln, (position) AS position FROM table WHERE position = 'X' ";
    
    //$get = @mysqli_query ($dbc, $select);
    
    
    
    $row = array(
    "id" => range(0,25),
    "fn" => range("A","Z"),
    "ln" => range("z","a"),
    "position" => range(50,75)
    );
    
    
    $get = true;
    
    // ------------------------- Run Query
    
    if ($get)
    
    {
    
    // ------------------------Start table
    
    echo "
    <div style='border-style: solid;'>
    
    <table align='left' border='1'>
    
    <tr>
    <td>People</td>
    </tr>
    
    
    <tr>
    <td>ID</td><td>First Name</td><td>Last Name</td><td>Position</td>
    </tr>";
    
    // ------------------------ Retrieve People
    
    $counter = 0;
    while ($counter < 26) {//$row = mysqli_fetch_array($get, MYSQLI_ASSOC))
    
    
    if ($color==1)
    
    	{echo ' <tr bgcolor= #47EA7D>
    			<td>' . $row['id'][$counter] . '</td><td>' . $row['fn'][$counter] . '</td><td>' . $row['ln'][$counter] . '</td><td>' . $row['position'][$counter] . '</td>
    			</tr>';
    			$color = '2';}
    
    
    				else
    
    					{echo ' <tr bgcolor= #A4C8B0>
    			<td>' . $row['id'][$counter] . '</td><td>' . $row['fn'][$counter] . '</td><td>' . $row['ln'][$counter] . '</td><td>' . $row['position'][$counter] . '</td>
    			</tr>	';
    			$color= '1';}
    
    
    // ----------------------- Close table
    
    $counter++;
    }
    echo "</div>
              </table>";
    
    
    
    //mysqli_free_result ($get);
    
    
    }
    
    // --------------------   IF ERROR WITH QUERY
    
    	else
    
    			{echo "Didn't connect";}
    
    
    
    // ---------------------- Spaces --> This is the code that doesn't appear to affect the space at the bottom of the table
    
    echo "<br />
              <br />
              <br />";
    
    
    ?>

  2. In ValidateForm() you return from the function as soon as the first condition is evaluated, regardless of what happens.

     

    I think you intended do something like this pseudocode:

     

    if (condition)

      true: push error into $errors array

      false: (nothing)

     

    if (othercondition)

      true: push error into $errors array

      false: (nothing)

     

     

    return $errors array

  3. date(String $format, [int $timestamp]);

     

    so probably something like:

    $time = date("F j, Y, g:i a", $_SERVER['REQUEST_TIME']);

    Though I think most people just do date("format", now());  where format is how you have it above.

     

    Test it out and see which gives you what you want.

  4. >=

     

    "There's your problem"

     

     

    for (expr1; expr2; expr3)

        statement

    The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop.

     

    In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and the nested statement(s) are executed. If it evaluates to FALSE, the execution of the loop ends.

     

    At the end of each iteration, expr3 is evaluated (executed).

     

  5. Shouldn't you be checking the value of $_POST['requests'] instead of $_SESSION['checkbox']?  From the code you gave us, all I can tell is that in your logic, you are looking at a session variable, but your above code is dealing with a form.  Is that it?

  6. Yes - I don't see any reason why you wouldn't be able to do that.  Syntactically, it seems fine.

     

     

    edit: You edited it while I was replying..  , but in the version I saw later you're missing a ) to match the empty( function.  (2nd if statement)

  7. Yes - for simple things, you might just have it modify a file like (requests.ini) and have PHP read the contents of that file at set intervals.

     

    However, if there are going to be multiple DJs, etc, etc, you may switch to using a database for statistical considerations later down the line.

  8. I've seen what you're talking about, and there are various ways to do this, so I'll speak in general terms.  If you have a specific example, you could investigate the source code yourself, or link it here and nicely ask someone to break down the "technologies" used.

     

    In general, to display one "website" as a subpage of another:

     

    You can use frames/iframes.  //not very widely used

     

    You can use javascript(ajax) and divs.  //more common

     

    I'm not 100% on the technologies, but I think they either load the page in another div, or even use javascript injection into the destination page.

  9. From the information you've given us, storing the two templates inline in the same PHP file would be fine.  Adding a database or fileloading (require/include) would likely be more overhead than needed, assuming your template is a fairly small amount of code.

     

    If you're talking about saving the "requests turned on/off" thing.. that's a slightly different story.  You could probably get away with it by using sessions and having the client pages check on intervals to see whether or not to display the template.

     

    Does that answer your question, or are you referring to something else?

  10. You're using a combination of a literal string and concatenation incorrectly.

     

    <?php
    if ($_POST['hid']==0)
    {
    header("Location: sample.php?aid=" . $aid);
    }
    ?>

     

    or

    <?php
    if ($_POST['hid']==0)
    {
    header('Location: sample.php?aid=' . $aid);
    }
    ?>

     

    Your method echos text of $aid rather than the value of the variable $aid I'm assuming.

  11. My personal preference, which I've found to be easier is to surround echo strings with double quotes, and then attributes within those strings with single quotes.  Only when working with Javascript inside those strings will I use escaped double quotes (\") around the outside.

     

    <?php if (isset($_SESSION['idx'])) {      
    echo "<div class='containerheader' id='titleTextImg'><strong>Military Attachés accredited in Egypt</strong>";
    echo "<a id='imageDivLink8' href=\"javascript:toggle5('contentDivImg8', 'imageDivLink8');\"><img src='images/x.gif' align='right'></a></div>";
    echo "<div class='container' id='contentDivImg8' style='font-size:15px; display:block; margin-bottom:5px;'>
            <a href='member_countries.php'><img src='images/worldmap.gif' width='300' height='184' alt='Member Countries' title='Member Countries' border='0' /></a>
            <br /><span style='font-size:12px;'>Click somewhere on the map to open the member countries page.</span></div><br />";}
          ?>  

  12. This example might get you some of the way there, but I don't have time to read up on the GD library right now.  Hopefully this might get you a little closer to your answer.  This is probably not the best way; I'm just trying to get it to work in general.

    <?php
    $body 	= imagecreatefrompng('body.png');
    $head 	= imagecreatefrompng('head.png');
    $armour	= imagecreatefrompng('armour.png');
    
    //innermost->outermost
    imagecopymerge($head, $body, 0, 0, 0, 0, 64, 102, 100);
    imagecopymerge($armour, $head, 0, 0, 0, 0, 64, 102, 100);
    
    header('Content-Type: image/png');
    imagepng($armour); //last image used
    
    //cleanup
    imagedestroy($body);
    imagedestroy($head);
    imagedestroy($armour);
    ?>

     

    If there are a reasonably finite number of combinations, I would recommend you generate them ahead of time, and just access the based on a mask of some sort.

×
×
  • 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.