cmps 26 Light Poster

Do you have Javascript enabled on your browser ?

Try this:
<a href="https://www.facebook.com/sharer/sharer.php?u=[YOUR LINK]" target="_blank">
Share on Facebook
</a>

cmps 26 Light Poster

Hello dany12 :)
I haven't worked with Python before, but I have worked with PHP and tried different frameworks. For me PHP can do pretty much everything I need from building simple website to creating a dynamic website connecting to Database etc ...
For PHP, codeigniter is my favorite framework for many reason:
Easy to understand, has a large library, easy guide tutorial, has a very big community compared to other frameworks for PHP
As I said, I don't know much about Python, but here's what I know about PHP :)
So hope you can find the best language and framework for you. Good Luck

cmps 26 Light Poster

Hello,
The concept is:
You have the array (A) with numbers:9,5,5,3
You have to loop through the values in A, and create a variable called max and by default set it to the first value in the array.
Create another array (B) that will hold the index for the max duplicated values, and finally create a counter variable called count.
Now you have to compare each value in the array with the max variable, the three conditions are:
if max > A[i] => do nothing
if max == A[i] => save i in B[count]
if max < A[i] => max = A[i] and count = 0 and B[count] = i

Code:

<?php

    $A = array{9,5,9,5,3};
    $max = $A[0];
    $count = 0;

    for($i=0; $i<count($A);$i++){
        if($A[$i] > $max){
            $max = $A[$i];
            $count = 0;
            $B[$count++] = $i;
        }elseif($A[$i] == $max){
            $B[$count++] = $i;
        }
    }

    for($i=0; $i< $count;$i++){
        echo "Index: ".$B[$i]." => ".$A[$B[i]]."<br/>";
    }
?>

This is just a way to do it, it will print at the end:
index 0 => 9
index 2 => 9

Please note that this code is not tested.
Good Luck

cmps 26 Light Poster

What is the error ?
Why don't you use scanf() ?
And you don't need to put &name, because name is already a pointer to the address of the first character of the array

void displayName(){
    char name[30];
    int number, x;

    printf("So..what is your name?\n");
    scanf("%s",name);
    printf("Nice to meet you %s, how many times would you like to be cloned?\n",name);
    scanf("%i", &number);
    for(x=0; x<number; x++){
        printf("%s",name);
    }
 }
cmps 26 Light Poster
    char string[] = "Hello";
    char c = string[0];
    printf("%c",c);

Is this what you want ?

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

try to use '!important' near the style you want to take place
example:

input[type="text"], textarea{
width:17em !important;
etc...
}
cmps 26 Light Poster
cmps 26 Light Poster

Congrats, but there is a default user for phpmyadmin, user "root" pass "" have you tried it ?

cmps 26 Light Poster
cmps 26 Light Poster

what is the error message ? Access Forbidden or what ?

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

First of all the server is running linux or windows ?
For linux you can use the lampp which is provided by the same company that created the xampp. To access the server from another computer, type the ip of the server in the browser so you will be able to access the xampp as a normal user. To access files you need an FTP software like filezilla.

cmps 26 Light Poster

Try this:
hyp = (hyp.charAt(0)+"").toUpperCase() + hyp.substring(1);
System.out.print(hyp);

cmps 26 Light Poster

No according to php.net he is doing it correctly :O

$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
cmps 26 Light Poster

Can you provide us with the output ?

cmps 26 Light Poster

$txtname = ucwords(strtolower($row ['First.Name'])) . ' '. ucwords(strtolower($row ['Last.Name']));
remove the replace function ...

Don't complicate your life ... :)

cmps 26 Light Poster

There are lot of solution for doing anything, one can use any solution as long as it's correct and effecient. So your code is fine ...

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

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

Okay the 2 classes are Node and BST
PSEUDOCODE:

class Node has
value of type integer
left and right node of type Node

class BST has
root of type Node
Insert method using recursion (prefered recursion)
Find method using recursion (remember it's a tree, so recursion should be your friend now)

For any implementation help feel free to ask, but you have to try it by yourself first as the rules of this forum requires :) Good Luck

cmps 26 Light Poster

you need a while loop, check this link:
http://www.w3schools.com/php/func_filesystem_fgets.asp

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

Do you want to put the footer at the extrem bottom ?
if yse:
change:
<body> => <body style="position:relative;">
<footer> => <footer style="position:absolute;bottom:0px;"> (maybe you are using DIV for the footer, if so do the same but footer become div)

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 sure ... html cant do this :) you can try php
good luck

cmps 26 Light Poster

Dear Sobias, the remember me check box is to create a cookie in the browser so the user stay logged in until he/she kill the cookie by logging out or if the cookie expires in x Days.
To do this from your website to login to another website:
- You have to check if the other website allows one to sign in from another website (example: facebook will not allow you)
- If it allows you, I suggest you to 'view-source' for the login page of the other website and save the form as it is. Of course you may change the style but make sure that if the form uses javascript, copy them as well.

I'm not sure if you want the php code for how to create a cookie since this topic is in the web design section, anyway I'am wondering why you want to let someone login to another website from your website ... If it's for testing it will be fine else, I recommend you to get a permission, because no one can trust logging to a website from another.

cmps 26 Light Poster

mysql_real_escape_string() is a must, you need to use it almost on every variable, in which value is taken from the user, to prevent SQL Injection.
Even if you have million users, if an action is applicable on one user, it will be applicable for all :)

cmps 26 Light Poster

Hello, it's enough, you are comparing username and password from user to database, the only two input that can identify the user are username and password, but make sure you are making the username unique.

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 'techxaidz', the problem is not very clear, what I understood is:
you have to make a class Library
then create classes: Book, Magazin etc ... that will inherite attributes and methods from the Library class. But the problem is that the relationship of the inheritence is "is"
For example: we have the following classes:
Circle, Rectangle, Square and Shape
Here we can use the inheritence:
Circle, Rectangle and Square will be subclass (will inherit) SHAPE
Because Circle is a Shape, Rectangle is a Shape etc ...
But Book is not a Library etc ...

Here's what I think you have to do:

Library.java

private Libarry[] items = new item[100]; //Array of size 100 that will contain books magazins etc ...
private int id;
private String title;
private int NumOfCopies;

private int counter = 0;

OTHER ATTRIBUTES
...
...

public void addItem(Library object){
    items[counter] = object;
    counter++;
}

....
....

LibraryHolding.java

main()
Library lib = new Library();
lib.add(new Book("CMPS",12 etc ....));

Book.java extends Library

public Book(String title,NumOfCopies etc...){
    super.setTitle(title);
    super.setNumOfCopies(NumOfCopies);
    etc...
}

Very Long Exercise but hope you got the concept, and hope this is what the prob wants.
I repeat, the problem is not professional and the relationship is not correct.

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

Did you check if the description field in databse is set to Text and not varchar ?

cmps 26 Light Poster

Dear 'garyjohnson', I think you are talking about something like this:
The user enters:
hello this is
amir
bwb

When echoing this, it will be displayed on one line only:
hello this isamirbwb

to fix this, you should use the function nl2br();

echo nl2br($description);

Hope this respond to your question.
NB: Same thing if you want to retrieve this from the database, save as $description, but echo it using nl2br()

Good Luck :)

cmps 26 Light Poster

Dear 'bradly', you forgot to float the div, this will work:

<div id="Mid_Content">
<div id="Left_Content" style="float:left;">
<h2>Best Rates </h2>
<p>
2012 has been a great year for cheap mortgage deals. The Bank of England rate is at an all time low and mortgage lenders having to compete for your business, mortgage rates have been consistently low. Approaching the right mortgage provider for your circumstances is essential to getting the best rate. </p><p>
</p><p>
At We-Remortgage our mortgage advisers are highly experienced professionals, they have the knowledge and expertise to help you choose the right deal with latest applicants receiving rates as low as 2.68%!
</p><p>
Complete our 30 second form and start saving!
</p><p>
</p></div>
<div id="Mid_point_Content" style="float:left; width:33%;">asdasd</div>
<div id="Right_Content" style="float:right; width:33%">Form</div>

</div>

Good Luck :)

cmps 26 Light Poster

After double checking, you have the div id="main" which is the left part to have a width of 550px;
So the table should be 550px unless you force it the be wider.
You are padding 22px (left+right) in each rectangle 'td', and you have 8 'td' per row 'tr'
so 8x22 = 176px on padding + 10px on margin-left for the div main, and for the first 2 rows, you used the <p> which has a 10px padding on each side so 20x8=160px
so in total you have 346px only on padding and margin.
I think it's a lot!!

So to solve this.
add this css at the end of of the style tag

#main table p {
    padding: 0;
}

and the problem is solved :)

cmps 26 Light Poster

Dear SPeed, try to remove the padding-left: 11px; or padding-right: 11px; for the td this will fix the size.

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 'Fiorentino01^', there are 2 ways to do this:

  • Write the full path
    Ex: <a href="http://www.domain.com/web-site/2/home.html">go to Home</a> (This will be placed in the page index.html) and same thing with home.html

  • Write the path starting from the location of the file you are coding
    Ex: you are coding the page index.html, just write <a href="../2/home.html">go to Home</a>

../ is to go to the upper folder (Parent directory)

Here's a good tutorial for HTML paths
http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/

Good Luck

cmps 26 Light Poster

Dear "Proglearner", Frist of all here's a link to the best HTML web tutorial:
(IMAGE TAG)
http://www.w3schools.com/html/html_images.asp

After reading this I think you will be able to more understand what is the src and how to use it.
I'll try to explain it in my own words:
<img src="images/test.jpg">
This is how we display an image in an html page.
<img> => image
src => source

THe src attribute will take the .html file directory as the main/default directory.
For example here src="images/test.jpg"
This means that in the same directory where the HTML file is located, there is a directory named 'images' which contain the file 'test.jpg'

Hope this was helpful, Good Luck ;)

cmps 26 Light Poster

Dear 'garyjohnson', since you posted this topic in the webdesign html css section, I will concider that you are not using the dynamic programming language PHP.
Using html css you just have to make another HTML page let's say the album is in file
named: albumName.html
Copy and paste this page again and name it albumName2.html
and make a link to this page by adding
<a href="albumName2.html">Next Page</a>
in the first page at any place you choose.
Now change the source of the images so they link to the 8 remaining.
If you are using PHP & MySQL let me know because here you will be using the pagination with the LIMIT option in MySQL.
Hope this is clear, for any other inforamtion feel free to ask.

cmps 26 Light Poster

Dear Amiyar, the code i wrote fetch for both id and not only the first one ...
Maybe you mean you want to do this:

 SELECT shipping_us FROM tbl_product WHERE prod_id=526 OR  prod_id=527

?

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

Dear Amiyar ... What is happening to you is very logical.
Lets debug what you are doing:

 echo $s_country;
    $sql2="SELECT prod_id FROM tbl_order_item WHERE order_id='$order_id'";
    $res=mysql_query($sql2) or die(mysql_error());
    $i=0;
    $j="";
    while($rs=mysql_fetch_array($res)){
        $j .= $rs['prod_id'];
        $i++;
    }

No syntax error ... but a logical error exists.
in the while loop you are doing this:
in the first loop j= 526;
in the second loop you are doing this "append to j 527" so j = 526527;

So j is no more the target id you want to fetch from database.
so what you want to do here is to put to put the code

if(trim($s_country)=='US' || trim($s_country=='United States' )){
    $sql3 = "SELECT shipping_us FROM tbl_product WHERE prod_id=".$j;
    $res=mysql_query($sql3) or die(mysql_error());
    $shipping_cost1=mysql_fetch_object($res);
}

inside the while loop:

echo $s_country;
        $sql2="SELECT prod_id FROM tbl_order_item WHERE order_id='$order_id'";
        $res=mysql_query($sql2) or die(mysql_error());
        $i=0;
        $j="";
        while($rs=mysql_fetch_array($res)){
            $j = $rs['prod_id']; //I removed the dot cuz i don't want to append
            if(trim($s_country)=='US' || trim($s_country=='United States' )){
                $sql3 = "SELECT shipping_us FROM tbl_product WHERE prod_id=".$j;
                $res=mysql_query($sql3) or die(mysql_error());
                $shipping_cost1=mysql_fetch_object($res);

                /*YOUR CODE GOES HERE*/
                echo theCalculation;
            }
            $i++;
        }

Hope you understand the logical error.
Good Luck

cmps 26 Light Poster

So the advantage of using a constructor over a setter is that a constructor can initialize more than a variable, which is what a setter does?

Yes you can say that :)
I'am sure that you will learn with time the hidden advantages of constructors,
good luck

cmps 26 Light Poster

Hello 'Violet_82', we can sometimes get rid of the constructor, the example you looked at may not be the best to judge if constructors are important or not. Look at this example, it may makes more sense:

Person.java

public class Person{
    private firstName;
    private lastName;
    private age;

    Person(String firstName,String lastName,int age){
        this.firstName = firstName; //this. is used to point to the variable defined at the top and not the parameter of the constructor
        this.lastName = lastName;
        this.age = age;
    }

    public void setFirstName(String firstName){
        this.firstName = firstName;
    }

    ....
    ....
    ....
}

Here's now how we use this:

Person aBoy = new Person("Hello","World",19);

isn't it more practicle that each time calling the setters ?
NB: the code is not tested, but hope you got the idea ... Good Luck