0

For example I have a order_number from MySQL database.

The code below will print out Order Number:order_number. I want to make a hyperlink to the order_number. Is it possible to do so?

while ($row = mysql_fetch_array($result)) {
     echo '<b>'.'Order Number: '.'</b>' .$row['order_number'].'<br />';
 }

Is this code below correct for the order_number hyperlink?

while ($row = mysql_fetch_array($result)) {
     echo '<b>'.'Order Number: '.'</b>' ."<a href="www.testpage.com/jobs/order_number">$row['order_number']</a>".'<br />';
 }

I'm even sure it is possible to increment each page with the new order_number.

i.e: order_number = 11111 --> www.testpage.com/jobs/11111

order_number = 22222 --> www.testpage.com/jobs/22222

3
  • Ah but what is the link for a specific order_number? http://website.com/orders/order_number, etc? Commented Aug 8, 2013 at 17:05
  • Sorry for not be specific, the link should www.website.com/jobs/order_number Commented Aug 8, 2013 at 17:08
  • I understand. See my solution. The order_number is linked within the url outputted. Commented Aug 8, 2013 at 17:17

5 Answers 5

1

Your quotes are mixed up. Try the example below. I put it on two lines to make it more readable.

while ($row = mysql_fetch_array($result)) {
     echo '<b>Order Number:</b>';
     echo '<a href="www.testpage.com/jobs/order_number">' . $row['order_number'] . '</a><br />';
}

I suppose you also should place the order number somewhere in the href attribute, maybe like this:

while ($row = mysql_fetch_array($result)) {
     echo '<b>Order Number:</b>';
     echo '<a href="www.testpage.com/jobs/' . $row['order_number'] . '">' . $row['order_number'] . '</a><br />';
}
Sign up to request clarification or add additional context in comments.

Comments

1

You needed to link the variable in the url that you are outputting as well. To easily create the string, I bound the variable from $row into a new variable.

while ($row = mysql_fetch_array($result)) {
    $order_num = $row['order_number']

    echo "<b>Order Number:</b>" .
         "<a href='www.testpage.com/jobs/$order_num'>$order_num</a><br />";
 }

Comments

1

Variables are accessed through double quotes and ignored in single quote cases...

Try

echo '<b>'.'Order Number: '.'</b><a href='www.website.com/jobs/"$row['order_number']"'>$row['order_number']</a>

Comments

1

You have a quote problem between ' and ".

while ($row = mysql_fetch_array($result)) {
     echo '<b>'.'Order Number: '.'</b>' ."<a href="www.testpage.com/jobs/order_number">$row['order_number']</a>".'<br />';
 }

As you can see you are using double quote when you start the link (a) tag. You should keep using the single quote.

while ($row = mysql_fetch_array($result)) {
     echo('<b>Order Number:</b><a href="www.testpage.com/jobs/order_number">'.$row['order_number'].'</a><br />');
 }

You also doesn't need to use that much quotes. You can have several string within the same quote.

Comments

1

Try like this

while ($row = mysql_fetch_array($result)) {
      echo '<b>'.'Order Number: '.'</b>' .'<a href="www.example.com/sample.php?orderNumber='.$row['order_number'].'">'.$row['order_number'].'</a><br />';
}

OR

while ($row = mysql_fetch_array($result)) {
     $orderNumber=$row['order_number'];
     echo "<b>Order Number : </b><a href='www.example.com/sample.php?orderNumber=$orderNumber'>$orderNumber</a>";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.