I have a database that returns information about a customer's jobs that have shipped. It displays correctly, but I would like the carrier name to be a link to the carrier's website so the customer can track it on line. I have the carrier's website listed in the database. how do I make the carrier's name print as a link to their website?
Any help would be greatly appreciated!

$resultb = mysql_query("SELECT * FROM orders WHERE mold='$mold' and shipdate is not null",$db);

                                         if ($myrow = mysql_fetch_array($resultb)) {

                      echo "<BR/><table cellpadding=\"3\" cellspacing=\"3\" border=\"0\">\n";

                      echo "<tr bgcolor=\"#B9B8B8\"><td><span class=\"bold\">Mold Number</span></td><td><span
class=\"bold\">Date Shipped</span></td><td><span class=\"bold\">Carrier</span></td><td><span class=\"bold\">Tracking Number,</span></td></tr>\n";

                      do {



                        printf("<tr bgcolor=\"#EAE8E8\"><td>%s</td><td>%s</td><td>%s</tr>\n", $myrow["mold"],$myrow["shipdate"], $myrow["carrier"], $myrow["tracking"]);

                                                  } while ($myrow = mysql_fetch_array($resultb));

                                                  }

Where is the carriers website address stored? Is it in the orders table? If not then you will need to modify your sql statement to perform a join to the table containing the carrier website address. You can then modify your do loop to build a standard href attibute around the carrier name.

Thanks Lafinboy,
The web address is located in the website field of the orders table, but I'm not sure how to build a standard href attibute around the carrier name.

Stick

Try this:

do {
 printf("<tr bgcolor=\"#EAE8E8\"><td>%s</td><td>%s</td><td><a href=\"%s\">%s</a></td><td>%s</td>\n", $myrow["mold"],$myrow["shipdate"], $myrow["carrier"], $myrow["tracking"]);
}

It gave me this error. "Warning: printf(): Too few arguments "

Sorry, missed out one of the carrier calls. Should read:

do {
 printf("<tr bgcolor=\"#EAE8E8\"><td>%s</td><td>%s</td><td><a href=\"%s\">%s</a></td><td>%s</td></tr>\n", $myrow["mold"],$myrow["shipdate"], $myrow["carrier"], $myrow["carrier"]
, $myrow["tracking"]);
}

How is the carriers url stored in the database? If it is just in the format www.carriersdomain.com then you will need to force the http:// onto the front of it, otherwise the system assumes it is a local path. Try:

do {
 printf("<tr bgcolor=\"#EAE8E8\"><td>%s</td><td>%s</td><td><a href=\"http://%s\">%s</a></td><td>%s</td></tr>\n", $myrow["mold"],$myrow["shipdate"], $myrow["carrier"], $myrow["carrier"]
, $myrow["tracking"]);
}

That gave me a result of http://www.mydomain.com/carriers name.
So I changed the script to
printf("<tr bgcolor=\"#EAE8E8\"><td>%s</td><td>%s</td><td><a href=\"http:\\%s\">%s</a></td><td>%s</td></tr>\n", $myrow["mold"],$myrow["shipdate"], $myrow["website"], $myrow["carrier"]
, $myrow["tracking"]);

That gave me a result of http://www.mydomain.com/www.carriersdomain.com.

So I changed the carriers web address in the database to http://www.carriersdomain.com.

That gave me a result of http://www.mydomain.com/http://www.carriersdomain.com.

I am using a mysql database, and have the field type set to varchar.
Is it possible that the field type is incorrect?

I have a test order set up in the database. If you would like to see how it is working, I can email you the domain with the user name and password for the test order.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.