cmps 26 Light Poster

Displaying a table needs basic HTML knowledge. If you want to learn the basics go to: www.w3schools.com
Here's how you do it:

...

if(isset($_POST['submit']) && !empty($_POST['submit'])){

    $result = ""; //USED LATER
    /*$term = $_POST['term']; THIS WORKS BUT FOR SECURITY ISSUES USE:*/
    $term = mysql_real_escape_string($_POST['term']);//AVOID MYSQL INJECTION

    $sql = mysql_query("SELECT * FROM `Find Your Gid` where Name like '%$term%'");

     if (mysql_num_rows($sql) <= 0) {
        // no results
        //echo 'No results found.'; BETTER ECHO LATER
        $error = "No result found";
    } else if ($term ="") {
        $error = "No name entered!";
    } else {
        $result .= "<table>";
        $result .="<tr><td>Name</td><td>Gid</td><td>Giftable</td></tr>";
        while ($row = mysql_fetch_array($sql)){
            $result .= '<tr>';
            $result .= '<td>'.$row['Name'].'</td>';
            $result .= '<td>'.$row['Gid'].'</td>';
            $result .= '<td>'.$row['Giftable'].'</td>';
            $result .= '</tr>';
        }
        $result .= "</table>"; 
    }
     mysql_close();
}

...
cmps 26 Light Poster
<?php
mysql_connect ("localhost", "","")  or die (mysql_error());
mysql_select_db ("");

if(isset($_POST['submit']) && !empty($_POST['submit'])){

    $result = ""; //USED LATER
    /*$term = $_POST['term']; THIS WORKS BUT FOR SECURITY ISSUES USE:*/
    $term = mysql_real_escape_string($_POST['term']);//AVOID MYSQL INJECTION

    $sql = mysql_query("SELECT * FROM `Find Your Gid` where Name like '%$term%'");

     if (mysql_num_rows($sql) <= 0) {
        // no results
        //echo 'No results found.'; BETTER ECHO LATER
        $error = "No result found";
    } else if ($term ="") {
        $error = "No name entered!";
    } else {
        $result .= "<fieldset>";
        while ($row = mysql_fetch_array($sql)){

            $result .= '<br/> Name: '.$row['Name'];
            $result .=  '<br/> Gid: '.$row['Gid'];
            $result .= '<br/> Giftable: '.$row['Giftable'];
            $reuslt .= '<br/><br/>';
            }
           $result .= "</fieldset>"; 
    }
     mysql_close();
}
?>


<html>
    <head>
        <title>FIND YOUR GID</title>
    </head>

    <body>

    <form action="findyourgid.php" method="post">
     Search: <input type="text" name="term" /><br />
    <input type="submit" name="submit" value="Submit" />
    </form>

    <div name="Results">
    <?php
    if(isset($error)){echo $error;}
    if(isset($result)){echo $result;}
    ?>
    </div>

    </body>
</html>

<script type="text/javascript">
var arrRequiredFields = [ "term" ];
window.onload = function() {
   document.forms[0].onsubmit = function() {
      for (var i = 0; i < arrRequiredFields.length; i++) {
         var field = document.forms[0].elements[arrRequiredFields[i]];
         if (field && field.value.length == 0) {
            alert("Missing Name of Food");
            field.focus();
            return false;
         }
      }
      return true;
   };
};
</script>

I didn't try this code but try to understand it and modify it to work as you want ...
Btw PHP code is almost every time inserted on the top of the page because you will use variable and results of the php process later in the display part which is the HTML …

cmps 26 Light Poster

Hello!! Recently I started using google webmaster tool for an ecommerce website. The problem is that google is displaying that some pages has duplicate meta descriptions. The pages that google is pointing to are: the product page and the review of this product.
However, the meta description in the product page and its review is not exactly the same. For example:
Procduct page: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Review of the product: Review: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
I've added the word "Review:" before the original meta description in the product review page.
Question: Shouldn't the word "Review:" make the meta description for the page unique so google won't mention is as duplicate ?
Or should the meta description be completely different ? I mean no common words with another page ?
I have 8 similar duplication of this type that google is considering them as duplicate, how to fix this ?
Thank you :)

cmps 26 Light Poster

Aha I haven't tried that before but thank you.
Yes you can do this with css by using the percentages. Here's a fast example:

<div style="width:30%; float:left; background-color:red;">This i 30%</div>
<div style="width:70%; float:left; background-color:blue;">This i 70%</div>

cmps 26 Light Poster

to do an online offline system u nees to set a column for the last_active to store when the user was lastly active (this is used in case the user close the browser without signing out)
and u need to set another column is_online to check if the user is online when logged in or offline when signed out
In this case, the condition to check if the user is online is:
check if the user is online and the last_active is less than 10min

cmps 26 Light Poster

Thank you, it can be helpful if the browser does not support javascript or it's disabled ...

<M/> commented: good point +0
cmps 26 Light Poster

okay i think that's becuz the $_POST['Name'] is not set in print.php.
actually u are redirecting to the page print.php and not submitting the input values ... In other words u may use the post in the save.php cuz the form action is pointing to save.php but not in print.php.
To fix this u can use the $_GET['name'] in print.php. Like this:

save.php
header('location:print.php?name='.$_POST['name']);

and in the print.php use:
I <?php echo $_GET['name'] ?> certified ....

cmps 26 Light Poster

you can easily fix that by using the percentage %. Let's say that the background div has an id of 'context', then the css would contain:

context:{width:100%};

if you don't want to complicate your self by opening the css file and save and refresh. Use the firebug plugin on firefox or use the inspect element of google chrome browser so you can preview changes directly on the browser without affecting your files. When you're ok with the width, apply the changes to your files.
Good luck

<M/> commented: ;) +8
cmps 26 Light Poster

Why I have a feeling that this is your homework ;)
anw heres a semi-answer ...
1 . the diff btw this.dollars and otherMoney.getDollars():
this.variable means refers to the variable in the current class where this.variable appears.
getDollars() is a function for the composite otherMoney which is also of type Money

2 . int newd = dollars + otherMoney.getDollars();
this means that getDollars() returns an Int

3 . this method can be called from the main by creating a new object of type Money

cmps 26 Light Poster

I think you have to define a variable of type file and pass it as parameter to the fgets():

<?php
    $file = fopen("file/games.csv","r");

    // Dump the games.csv file into an array
    $games = fgets($file);
    // Parse the array
    foreach($games as $game)
    {
    echo "{$game}";
    }

    fclose($file);
    ?>
cmps 26 Light Poster

I actually forgot to insert the link for the website tuorial in Q5
http://javabrains.koushik.org/p/home.html
Is it good to start with ?

cmps 26 Light Poster

Try this code, it worked for me ;)

<?php
$total=
"AA AA
AA AA
BB BB
BB BB
BB BB
CC CC
BB BB
BB BB
AA AA
CC CC
DD DD
DD DD"
;
$keyarr=explode("\n",$total);
$int=sizeof($keyarr);

$i=0;
$tmp = array();
$cur = 0;
$found = false;
while($i<$int){
    $found = false;
    for($j=0; $j<sizeof($tmp);$j++){
        if(trim(preg_replace('/\s\s+/', ' ', $keyarr[$i])) == trim(preg_replace('/\s\s+/', ' ', $tmp[$j]))){
            $found = true;
        }
    }

    if(!$found){
        $tmp[$cur++] = $keyarr[$i];
    }

    $i++;
}

foreach($tmp as $element){
    echo $element."<br>";
}
?>
cmps 26 Light Poster

Yes 100%

Having said all that, I'm sure we both agree that this is one of the worst designed and specified exercises ever, and OP deserves all the help he can get.

It could be an idea to retrieve an Item using ID but I don't know why my idea deserved a -1 :o
Let me explain more why I suggested the int index as parameter:
Let's say he added 100 item (Books and Magazins), he can now do a for loop that will iterat on all the items and do whatever task he wants to do.
Example:
for(int i=0; i < 100; i++)
System.out.println(lib.retrieveItem(i).getTitle());

Just by having the index as parameter, he can now do lot of things like for example count how many Books or Magazins are available in the lib, Display only items with ID > 2000 etc ...

Hope you understood my point. Regards

cmps 26 Light Poster

Dear JamesCherrill, I can't see why is retrieveItem is pointless! The items array is private and you cannot access it from other classes (Tester/Driver) so you have to create a retrieveItem() for the items array so you can get the elements.
Is there a way to get a certain element from the private items array ?
I though about it like the arrayList in which there is a function called get(), that will get a specific index from the private Data array.
Logically it makes sense when you use lib.retrieveItem(#); It will return an Item of type Library that will be treated as Book or Magazin depending on what the real type is.

cmps 26 Light Poster

Dear techxaidz, retrieveItem() method:

public Library retrieveItem(int index){
    return items[index];
}

The retrieveItem(int index) method is used is such example:

Library lib = new Library();
lib.addItem(new Book(....));
lib.addItem(new Magazin(....));
lib.addItem(new Book(....));

System.out.print(lib.retrieveItem(0).getTitle());

Good Luck, and yes I think you have to try to start writing some code. Here we can give you Algorithm, Idea, Some Pseudocode and correct your code, but we cannot solve the Execise ;)

cmps 26 Light Poster

Dear earlxph8, if you know how to use html this will be very easy for you.

In html file you directly write
<p>Sample test</p>

however in PHP, you have to echo the html:
<?php echo "<p>Sample test</p>";?>

When you echo a string, it will be treated as a html text, so all html tags will work when echoed.
What is even more important is that you can edit the style of the tags exactly like you do in html, taking the same example:

HTML:

<p style="text-decoration:underline;">Sample Test</p>

In PHP:

<?php echo "<p style=\"text-decoration:underline;\">Sample Test</p>";?> *//the \ is to tell PHP that the string is not finished yet, so it will not end it.*

OR

<?php echo '<p style="text-decoration:underline;">Sample Test</p>';?> /*//no need for the \*/

With MYSQL, you can store an HTML block with it's style as it is in the database. When you echo the data using php, it will be treated as HTML.

Good Luck, For any other information feel free to ask :)

cmps 26 Light Poster

Tell us more what you have tried or what you know about database, which one you are using?
But before to start doing everything directly on the computer, and since you are not very sure about the inforamtion you are going to insert in the DB, try to draw the tables and make the connections on a paper so you can easily create the tables in your DB

tux4life commented: Good suggestion :-) +13
cmps 26 Light Poster

Dear Ilda, I don't really understand, you need help in what data can be added to the database or how to create a database from zero ?
Please be more specific, Thank you :)

NB: You have to put some self effort and of course we will help you :)
Good Luck

cmps 26 Light Poster

Dear Ronald, this is my first year of computer science, in my own experience of 2 years as a PHP developer and 1 year of JAVA:
If you know how to use PHP as an OOP (Classes) this will skip a big part of learning JAVA.
However there are some differences in declaring variables and functions and some other declarations and getting and importing information ...
Since I have accomplished the first year in learning and practicing JAVA, I can tell you that JAVA is more detailed and direct (you have to specify each function and variable if it's an integer or string or etc...). But personally, I didn't find any difficulties in learning JAVA, since almost every chapter I was able to link it to a chapter in PHP. Only the way of writting differ.
Brief, I recommend you to start and within less than 3 years of practicing java (REAL PRACTICE AND DISCOVERING) you will be ready for any position.

Good Luck

cmps 26 Light Poster

Dear Chinmay, if you want to modify the code or test new codes on wordpress, you can copy the folder that contain all the wordpress files and paste it anywhere you want in public_html folder .. name it something that no one can guess it (you can protect it with password from an option in the cpanel).
So when you do those steps .. you will have the same live activities running on your test wordpress blog. You can now change, add or remove any part of the website code without changing the original wordpress blog code.
NB: Don't delete or edit posts, articles because this will affect the original wordpress too since both are connected to the same database.

cmps 26 Light Poster

Hello again 'viveksraman', the problem is that you are doing a while loop in which the first condition is false, in other words
while($row = mysql_fetch_assoc($retr))
is the same as
while(false) which will not read the content and will directly jump to the last close curly brkt

while($row = mysql_fetch_assoc($retr))
is only used if you are sure you have more than 1 row as a result of you query "SELECt ..."

since here there is no result, mysql_num_rows($retr) = 0;
$row = mysql_fetch_assoc($retr) is $row = false
therefor while(false) and the body is not executed

I want to repeat one thing, in checking username and password, in most cases we don't use while, cuz username are unique, but it's not a problem if you use it :)
to fix your code

SOLUTION OF YOU CODE:
1 - Back to your code, remove the else that is not executing and will never.
2 (First Method) - And you can add a boolean variable like found = false; before the while loop.
Inside the while loop write found = true;
and after exiting the while loop, write this condition

if(!found)
    echo $un . " not found";

2 (Second Method) - you can simply add this after the exiting the while loop:

if(mysql_num_rows($retr) == 0)
    echo $un . " not found";

Hope I was clear in my explanation :)
Good Luck

cmps 26 Light Poster

I just noticed that you want the option, Password doesn't match. OK
Just replace this in my previous code:
I recommend you to try both codes cuz you may use the first code block in your future ;)

mysql_select_db($database , $connection) or die(mysql_error());
$query = mysql_query("SELECT uname,password FROM user WHERE uname = '$un'");
$row = mysql_fetch_assoc($query);
$num_rows = mysql_num_rows($query);

//I considered the user is unique, if not change '== 1' to '> 0'
if($num_rows == 1){
    if($ps != $row['password']){
        echo "Password doesn't match";
    }else
    {
        echo "Welcome " . $row['uname'];
    }
}else
{
    echo $un." not found";
}

Good Luck
PS: THE CODE IS WRITTEN DIRECTLY HERE AND NOT TESTED

cmps 26 Light Poster

Hello 'viveksraman'.

You have to debug this by echoing before and after the conditional statements, and by adding the "or die(mysql_error());" after a function (check later in my code).

Or try to put this $row = mysql_fetch_assoc($retr); just before the while.

Anyway you can add this to your code
$row_num = mysql_num_rows($retr);
this will return the number of rows found in the database, if it's 0 than nothing found, if you want the username to be unique then the variable should be equal to one and NOT greater than one!!

Here's how I write your idea:

$connection = mysql_pconnect("localhost","root","password") or die(mysql_error());
$database = "amirbwb";

$un = $_GET['usname'];
$ps = $_GET['passwd'];

mysql_select_db($database , $connection) or die(mysql_error());
$query = mysql_query("SELECT uname,password FROM user WHERE uname = '$un' AND password = '$ps'");
$row = mysql_fetch_assoc($query);
$num_rows = mysql_num_rows($query);

//I considered the user is unique, if not change '== 1' to '> 0'
if($num_rows == 1){
    echo "Hello " . $row['uname'];
}else
{
    echo $un." not found";
}

PS: THE CODE IS WRITTEN DIRECTLY HERE AND NOT TESTED

cmps 26 Light Poster
$sql="name, price from table1";
echo "<tr><td>Name</td><td>>Price</td></tr>";
if ($result=mysql_query($sql)) {
while ($row=mysql_fetch_assoc($result)) {
echo "<td>".$row['name']."</td>";
echo "<td>".$row['price']."</td></tr>";}}

Try this:

Dunno the if condition what it does but anyway:

while ($row=mysql_fetch_assoc($result)) {
     if($name == $row['name']){
         echo ", ".$row['price'];
     }else{
        echo "<br/>";
        echo $row['name'] . ", ";
        echo $row['price'];
    }
    $name = $row['name'];
}

Good Luck

cmps 26 Light Poster

Creating a website and buying a domain name are two totally different things.
If you want to create a website, you have to know how to code in HTML CSS (Minimum), and if you are planning for a more dynamic website you have to know PHP & MySQL.

Concerning the domain name, if you want free hosting, your domain name will look like this www.devid.*********.com
********* is a name generated by the website during your registration, and probably it will ask you for the random word available so you can select one (Personally I don't like that, and it's not serious, but useful if you are testing the life of a website and how everything works ...)
And as '<MICHAEL>' said, www.000webhost.com is good for free hosting.

If you want a more serious website, buy a domain name with hosting, it will cost you about 3-6$/month depending on which web hosting company you are buying from.
Some recommended companies are: Bluehost.com and GoDaddy.com

Good Luck

<M/> commented: Good info For Dummies :) +5
cmps 26 Light Poster

Hello 'meowmonkey', not sure if that what you want ... Print a rectangle of y lines and x item on every line
Anw here's the code:

int Y = 4;
int X = 12;

for(int y=0; y < Y; y++){
    for(int x=0; x < X; x++){
        System.out.print("#");
    }
    System.out.println();
}