Menster 38 Junior Poster

Amost forgot, dont forget to initialize $sqlExtra to nothing above your switch statement and don't forget to include a default case.
Just ask if you need help again.

Menster 38 Junior Poster

Sure do,

What you need to do is the following:
1) Create a list of all of the attributes of your mysql table you would like to sort the table by.
2) Organize these into a switch statement at the top of your page in php, eg:

$sortby = intval($_GET['sort']);
switch ($sortby)
{
   case 1:
   {
          $sqlExtra = "ORDER BY name ASC";
    };break;
   case 2:
   {
          $sqlExtra = "ORDER BY name DESC";
    };break;
  //etc with the rest of the attributes
}

And then, after the switch statement append the $sqlExtra to your sql statement, eg:

$sql = "SELECT values FROM table ".$sqlExtra;

3) Now all you need is a bunch of links above or below or wherever relative to your table which must link back to this page but with a $_GET[] variable specified for 'sort', eg:

<a href="thispage.php?sort=1">Sort by name (A-Z)</a>
<a href="thispage.php?sort=2">Sort by name (Z-A)</a>

Good luck

Menster 38 Junior Poster

Write an algorithm in Javascript that can solve an np-complete problem in quadratic time. Thats always a good one, plus if you actually crack it you'll probably win a nobel prize.

Menster 38 Junior Poster

If you're new to php/mysql development, have a look at XAMPP, i've been using it for 7 months now without problems. The mysql front-end phpMyAdmin is excellent.

Menster 38 Junior Poster

P.S Forgot to mention South Africa is the BEST. (Not really, just Jo'burg and Pretoria, but you don't meet too many South Africans in the online community)

Menster 38 Junior Poster

Hi there,
Nothing leaps out at me as being wrong with your code, except it being a little incomplete. Eg your php side AJAX file doesn't echo the output or give any of the option elements any values. You could try this: Instead of replacing the entire select element with your ajax call, only replace the <option> elements. Ie, put the "cityDiv" tags inside the select tags and dont return the select tags with the ajax.

Good luck

Menster 38 Junior Poster

But, if you leave out the anchor tag the styles you've applied won't work... but i suppose you could just change them from a:hover etc.
to div:hover.

Menster 38 Junior Poster

I'll just say exactly what one of my 2nd year lecturers said to me: "There is no ultimate language or method, each one is better for something and terrible at something else, and because of this, sticking to one language will be your biggest downfall."

What I'm saying is that you need to research all of them and decide which ones you will use for the task at hand, eg: JavaScript makes for better interactivity but may be blocked by certain browsers. PHP makes for quick and easy coding which may become corrupted after many changes, whereas ASP more or less forces you to follow the OOP paradigm which will require unecessary effort for small jobs.

Menster 38 Junior Poster

Hi there, give this a go:

echo "<h2>Current Items and Quantities:</h2>\n";
      echo "<table width=\"100%\" cellpadding=\"1\" border=\"1\">\n"; 
	   $query = "SELECT description, quantity from products";
      $result = mysql_query($query);
   while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
 {
	    $description = $row['description'];
            $quantity = $row['quantity']; 
	    echo "<tr><td>$description</td><td>$quantity</td></tr>\n";
}		  
      echo "</table>\n";

This construct will loop through all the result sets return by the SQL and stop automatically after it has read the last one.

Good luck

Menster 38 Junior Poster

The human race will be destroyed by de-evolution:
Where stupid people outbreed smart people (as is currently happening) to a point where the human gene pool is reduced to the depth of a teaspoon at which point they'll all stab/bite/set fire to/blow each other up -or- due to the lack of genetic variation and the amont of genetic defects on the rise, a disease (like bird-flu) will pitch up and wipe them out.

Menster 38 Junior Poster

Hi there, have you tried:

<div id="blah" onclick="window.location = 'Your reference here'">
<a href="You can leave this blank">Your text here</a>
</div>
Menster 38 Junior Poster

Hi there,

I'm not quite sure what you're up to. Are you coding your own front-end for a database or are you using a proprietary tool like phpMyAdmin? If the latter then you are pretty much stuck with what they give you unless you actually want to dig through hundreds of lines of code looking for what you need. However the former is quite a simple exercise.

Menster 38 Junior Poster

Use a file area like this

<input type="file" name="upload[]" >

then in you php script

foreach($_FILES['upload'] AS $file)
{
//HERE YOU DO YOUR FILE SAVING
//For the file array
}
Menster 38 Junior Poster

I you are looking for a mail handling solution written in php then the guys at squirrelmail have already beaten you to it with their excellent solution. I you wanted to start your own online mail servise (like gmail, or webmail) then their solution will also scale to your needs, HOWEVER the amount of diskspace and bandwidth required to run such a solution effectively for more than a handful of clients is inordinate, not to mention the fact that you'll need redundant servers and load handling servers and all that kind of infrastructure to stop this thing from falling flat on it's face.

But if you're still interested, just google "squirrelmail". Their main site will be your first result.

Good luck

Menster 38 Junior Poster

Here, I use an array to prevent values from recurring after they have occured once.

$arr = array();
$values = array();
while (count($values) < 100)
{

$value = intval(rand(1, 100));
if (!in_array($value,$arr) 
{
array_push($arr,$value);
if ($value < 80)
{
$sales_code = 'VW';
} else if (($value > 79) && ($value <= 86)) {
$sales_code = 'DF';
} else if (($value > 86) && ($value <= 93)) {
$sales_code = 'RK';
} else if (($value > 93) && ($value <= 100)) {
$sales_code = 'DI';
}
array_push($values,$sales_code);
} else {
break;
}
}
Menster 38 Junior Poster
$value = intval(rand(1, 100));
if ($value < 80)
{
$sales_code = 'VW';
} else if (($value > 79) && ($value <= 86)) {
$sales_code = 'DF';
} else if (($value > 86) && ($value <= 93)) {
$sales_code = 'RK';
} else if (($value > 93) && ($value <= 100)) {
$sales_code = 'DI';
}

Hi there, hope this code snippet helps. Based on a random int, so it's gonna be random, but by the law of averages it'll work for what you need.

Menster 38 Junior Poster

Hi there,
Just to clarify, when you pull a date from the database and echo it, it appears in the format DD-MM-YYYY hh-mm-ss.
If thats the case and you just want the date part of the string, you can simply use substr() to get the part you want eg:

$date = substr($dateFromDB,0,10);
echo $date;

if you want to use that date for data manipulation you are gonna have to do it a little differently:

$day = substr($dateFromDB,0,2);
$month = substr($dateFromDB,3,2);
$year = substr($dateFromDB,6,4);
$date = new DateTime();
$date->setDate($year,$month,$day);
$date = $date->format("d-m-Y");

Good luck, hope this helped.

Menster 38 Junior Poster

Sure thing, try this:

<?php
for ($i =0; $i < $ValuenumtableChildren; $i++)
{
$value = htmlentities($Valuesibling[$i]);
echo "<a href=\"viewingdetails.php?name=".$value."\"</a>";
}
?>

htmlentities() takes special characters (like < > @ # $ % etc.) and changes them to their html escape codes, for example '<' is translated into '&lt;'. This will help the browser see that the space in your link's target doesn't terminate the tag.

Menster 38 Junior Poster

Hi there,
What you could try is changing your link from instead of having an href attribute, make an onclick attribute and put that line of javascript from your popup.php file into the onclick's value without the script tags etc. Example: <a onclick='window.open('Contact-Sms-Centre.php','new_window1','status=1,scrollbars=0,resizable=0,menu=no,left=450,top=2 ....) '>Contact</a>

I'm not sure if this will work for you because I'm not 100% sure what you're trying to achieve, but good luck. Let me know if it works :)

Menster 38 Junior Poster

It could be the spaces, run the values thru the htmlentities() function
and try again, but i can't see any reason why that link wouldn't work as it is in your last post.

Menster 38 Junior Poster

Hi there,
PHP's mail() function should work just fine for what you're doing as I've used it many times for the exact same thing with no problems.

For alternatives, the only 2 I know of are PEAR's mail function which (obviously) requires the PEAR libraries on your web server. For more documentation go to pear.php.net . The other alternative is directly opening a connection to your smtp server using php's socket functions, for more info on that go to http://www.php.net and search for 'socket'. But both of these ways are far more complex than just using mail() (which does run on smtp btw).

The only reason I can think of it failing occasionally would be something to do with your mail server, not the code.

Menster 38 Junior Poster

Hi there, from the past couple of posts, you guys are on the right track, it just seems that no-one remembered to close the anchor tag properly, it should be like this:

#
<?php
#
for ($i =0; $i < $ValuenumtableChildren; $i++)
#
{
#
echo '<a href="viewingdetails.php?name='.$Valuechild[$i].'">LINK TEXT GOES HERE</a>';
#
}
#
?>
Menster 38 Junior Poster

Hi there,
Try instead of the check $phone == '' , use if (empty($phone) || !isset($phone))

Menster 38 Junior Poster

Hi there,
The problem is that you are calling javascript from inside your php which is outside of it's name space. What you gotta do is in your php file : echo "<script>fcnX('home.php')</script>"; in the middle of your head section and the function will automatically be called when the page loads.

Menster 38 Junior Poster

Have you tried this: <script> this.close() </script>