Jump to content

Recommended Posts

$sql = "SELECT LEFT(websites_url, 1) AS 'websites_url_letter', websites_url
         FROM websites
        [b] WHERE websites_url_letter='$letter' [/b]
         ORDER BY websites_url ASC;";

hi it says

#1054 - Unknown column 'websites_url_letter' in 'where clause'

is there any way round this please?
Link to comment
https://forums.phpfreaks.com/topic/34809-help-on-sql-statement/
Share on other sites

You have to use the original column name.

$sql = "SELECT LEFT(websites_url, 1) AS 'websites_url_letter', websites_url
          FROM websites
        WHERE websites_url='$letter'
          ORDER BY websites_url ASC;";

You might be able to use the HAVING clause. I don't know the specifics of it, but someone else might be able to let us know if it will work.

Cheers,
Dave.
Link to comment
https://forums.phpfreaks.com/topic/34809-help-on-sql-statement/#findComment-164086
Share on other sites

[quote author=brown2005 link=topic=123062.msg508214#msg508214 date=1169162562]
$sql = "SELECT LEFT(websites_url, 1) AS 'websites_url_letter', websites_url
          FROM websites
        [b] WHERE websites_url_letter='$letter' [/b]
          ORDER BY websites_url ASC;";

hi it says

#1054 - Unknown column 'websites_url_letter' in 'where clause'

is there any way round this please?
[/quote]
$sql = "SELECT LEFT(websites_url, 1) AS 'websites_url_letter', websites_url
          FROM websites
        [b] WHERE LEFT(websites_url, 1)='$letter' [/b]
          ORDER BY websites_url ASC;";

or something like:

$sql = "SELECT LEFT(websites_url, 1) AS 'websites_url_letter', websites_url
          FROM websites
        [b] WHERE websites_url LIKE '$letter%' [/b]
          ORDER BY websites_url ASC;";
Link to comment
https://forums.phpfreaks.com/topic/34809-help-on-sql-statement/#findComment-164089
Share on other sites

yeah cool that works, right but now i have a function called

StripUrl();

which removes the first part of a url say

http://www.url.com

and function leaves

url.com

now i want to do the LEFT(websites_url, 1) as 'websites_url_letter' on url.com and not http://www.url.com

any ideas please?
Link to comment
https://forums.phpfreaks.com/topic/34809-help-on-sql-statement/#findComment-164332
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.